0

Here's my current IF, ELSE code:

        if ($mysqli->query($query)) {
            $success .= "<li>" . $name . "</li>";
            $success_count++;
        } else {
          //echo "Error: " . $query . "<br>" . $mysqli->error;
          $fail .= "<li>" . $name . "<br>" . $mysqli->error . "</li>";
          $fail_count++;
        }

Above the loop code is the variable declaration:

  $success = $fail = "";
  $success_count = $fail_count = 0;

Here is the ID (and NAME) declaration:

      $id = isset($Row[0]) ? $Row[0] : '';
      $name = isset($Row[1]) ? $Row[1] : '';

How do I modify the INSERT code so that if the ID already exists in the database, I want it to UPDATE the existing data. I know it should be something like this:

    if ($mysqli->query($query)) {
        $success .= "<li>" . $name . "</li>";
        $success_count++;
    }
    else {
      $id == TRUE //this is the code I am confused with
        UPDATE
          //update code here
      else {
      //echo "Error: " . $query . "<br>" . $mysqli->error;
      $fail .= "<li>" . $name . "<br>" . $mysqli->error . "</li>";
      $fail_count++;
    }
   }
Thomas
  • 73
  • 8

0 Answers0