Search code examples
mysqlsqlsql-inserton-duplicate-key

MySQL On Duplicate Insert


I'm new to MySQL so I can't figure out whats wrong in the syntax.

$sql = "INSERT INTO UsersTest (user_ip, email, firstname, lastname, city, state, country) VALUES ('$user_ip', '$email', '$firstname', '$lastname', '$city', '$state', '$country') ON DUPLICATE KEY UPDATE (user_ip = '$user_ip', firstname = '$firstname', lastname = '$lastname', city = '$city', state = '$state', country = '$country')";

Error:

You have an error in your SQL syntax; check the manual that corresponds to your MySQL server version for the right syntax to use near '(user_ip = ...

All the variables exists and are printed correctly.


Solution

  • Removing the parenthesis around the duplicate key update expressions should do the trick.