Page 1 of 1

Insert/Update Question

Posted: Thu Feb 05, 2004 1:22 pm
by cto1mac
Here is my code:

$updated_info = "INSERT INTO Roster (fname, lname, email, phone) VALUES ('$_POST[fname]', '$_POST[lname]', '$_POST[email]', '$_POST[phone]') WHERE id = " . $id

I get an error:

Invalid syntax near 'WHERE id = 4'.

What am I doing wrong??
Thanks

Posted: Thu Feb 05, 2004 1:24 pm
by Weirdan
Why do you think that INSERT supports WHERE clause?

Posted: Thu Feb 05, 2004 1:24 pm
by malcolmboston
edited due to above post

good point, god im tired today

Code: Select all

$updated_info = "INSERT INTO Roster (fname, lname, email, phone) VALUES ('$_POST[fname]', '$_POST[lname]', '$_POST[email]', '$_POST[phone]') WHERE id = " . $id
for starters.....

Code: Select all

$updated_info = "INSERT INTO Roster (fname, lname, email, phone) VALUES ('$_POST[fname]', '$_POST[lname]', '$_POST[email]', '$_POST[phone]') WHERE id = " . $id""
does that work?

Posted: Thu Feb 05, 2004 3:09 pm
by Unipus
malcolm, you must really be tired! there is no such thing as WHERE in an INSERT statement. You either need to remove it or change your INSERT to an UPDATE.

Posted: Fri Feb 06, 2004 2:41 am
by twigletmac
Good way to check invalid syntax, look at the actual syntax:
http://www.mysql.com/doc/en/INSERT.html

Mac

Posted: Fri Feb 06, 2004 6:20 am
by cto1mac
Yeah you guys are right. I solved it by using the:
UPDATE Roster SET .....

But thanks for the help.