Search code examples
sqlmysqlinsertmysql-error-1064

SQL Query Error


What is wrong with this Query?

INSERT INTO Registration 
  (`Status`, `String`) 
VALUES 
  ('Confirmed', '0') 
WHERE `String` = '". mysql_real_escape_string($user) ."'

1A:

UPDATE Registration 
       `Status` = 'Confirmed', 
       `String` = '0' 
 WHERE `String` = '". mysql_real_escape_string($user) ."'

Solution

  • Use:

    UPDATE Registration 
       SET `Status` = 'Confirmed', 
           `String` = '0' 
     WHERE `String` = '". mysql_real_escape_string($user) ."'
    

    INSERT is for brand-new records; if you are change values associated to an existing value -- you need to use UPDATE.

    Reference: