0

i am trying to insert data if user exists in duplicate row if not then insert data in new row i am trying but failed but is problem here please help me

$result = "SELECT * FROM coder WHERE name='".$name."'";
$sql = $conn->query($result);
if ($sql->num_rows > 0) {

    $result = mysqli_query("UPDATE coder SET stuts=1 WHERE name='Basic'".$conn);

    while($row = mysqli_fetch_array($result)){
        echo $row['Name'];
    }

} else {
    $sql = "INSERT INTO coder (Name, Startdate, Enddate, Users, Documenttype)
    VALUES ('$name', '$start', '$end', '$users', '$Documenttype')";

}
Qirel
  • 21,424
  • 7
  • 36
  • 54
  • This ""UPDATE coder SET stuts=1 WHERE name='Basic'"" is updating a single record regardless of the $name value. – jeff Nov 30 '16 at 13:39
  • `WHERE name='Basic'".$conn);` what is that `$conn` doing *there*? Concatenated to the SQL-string? Should be `mysqli_query($conn, "UPDATE...` instead – Qirel Nov 30 '16 at 13:40
  • And you're also trying to fetch the result of an update, doesn't work that way - and would give you warnings about that. Question is also somewhat unclear, can you update the description of your question to something that makes a bit more sense? :-) – Qirel Nov 30 '16 at 13:43
  • your question is answered [here](http://stackoverflow.com/questions/4205181/insert-into-a-mysql-table-or-update-if-exists). – Dragos Nov 30 '16 at 13:56
  • Yes sure sir Qirel Thanks for your interest. sir i am developing a web app where multi-pal user can login and can upload his data for example one user Mr. Jhon come to my website and create a profile after that goes a uploading section where he can upload file and log out and next user come to my website with the name of Qirel and perform same task and logout both user data display in their section in the form of rows. after some days Mr.Jhon come back and upload one more file that time not show that file in new section. continue.... – Muhammad Imran Nov 30 '16 at 14:00
  • first system check user name if it is exiting then uploaded file should go in the same section where first file located if not then insert new row please can you help me i trying but failed can you rewrite this code for me i will be thank full to you – Muhammad Imran Nov 30 '16 at 14:01
  • `$result = mysqli_query("UPDATE coder SET stuts=1 WHERE name='Basic'".$conn);` that's failing and probably `$row['Name']` with uppercase `N` as per `WHERE name`. Check for errors; you're not doing that. – Funk Forty Niner Nov 30 '16 at 14:43

0 Answers0