Insert/Update Question

Questions about the MySQL, PostgreSQL, and most other databases, as well as using it with PHP can be asked here.

Moderator: General Moderators

Post Reply
User avatar
cto1mac
Forum Commoner
Posts: 54
Joined: Tue Jan 27, 2004 6:11 am
Location: Virginia Beach, VA

Insert/Update Question

Post 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
User avatar
Weirdan
Moderator
Posts: 5978
Joined: Mon Nov 03, 2003 6:13 pm
Location: Odessa, Ukraine

Post by Weirdan »

Why do you think that INSERT supports WHERE clause?
malcolmboston
DevNet Resident
Posts: 1826
Joined: Tue Nov 18, 2003 1:09 pm
Location: Middlesbrough, UK

Post 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?
Unipus
Forum Contributor
Posts: 409
Joined: Tue Aug 26, 2003 2:06 pm
Location: Los Angeles, CA

Post 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.
User avatar
twigletmac
Her Royal Site Adminness
Posts: 5371
Joined: Tue Apr 23, 2002 2:21 am
Location: Essex, UK

Post by twigletmac »

Good way to check invalid syntax, look at the actual syntax:
http://www.mysql.com/doc/en/INSERT.html

Mac
User avatar
cto1mac
Forum Commoner
Posts: 54
Joined: Tue Jan 27, 2004 6:11 am
Location: Virginia Beach, VA

Post by cto1mac »

Yeah you guys are right. I solved it by using the:
UPDATE Roster SET .....

But thanks for the help.
Post Reply