0

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.

2 Answers 2

3

The on duplicate key update clause shouldn't have parentheses around it:

$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'";
Sign up to request clarification or add additional context in comments.

Comments

2

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

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.