views:

37

answers:

3

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) ."'
+5  A: 

You don't specify a WHERE clause on an INSERT query, only UPDATE.

Phil Brown
Oh, that makes sense! So, I would need to to this [see 1A on original post]?
Zachary Brown
Yes Zach, that looks right for your 1A.
JClaspill
+1  A: 

It might be worth combing over this page: http://dev.mysql.com/doc/refman/5.1/en/insert.html

PureForm
+2  A: 

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:

OMG Ponies