More mysql syntax error?

PHP programming forum. Ask questions or help people concerning PHP code. Don't understand a function? Need help implementing a class? Don't understand a class? Here is where to ask. Remember to do your homework!

Moderator: General Moderators

Post Reply
User avatar
cap2cap10
Forum Contributor
Posts: 158
Joined: Mon Apr 14, 2008 11:06 pm

More mysql syntax error?

Post by cap2cap10 »

Hello, again php technorati,

:banghead: This time I keep getting this error:

Query failed: 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 'WHERE 'userID' = 32' at line 1


What is wrong with this Statement?
Here is the code:

Code: Select all

$query ="INSERT INTO `js_profile` (candidateID) VALUES ('$candidateID') WHERE 'userID' = $userID";
$result = mysql_query($query) or die('Query failed: ' . mysql_error());
 
$query = "INSERT INTO `js_account` (candidateID) VALUES ('$candidateID') WHERE 'userID' = $userID";
$result = mysql_query($query) or die('Query failed: ' . mysql_error());
I have tried different variations.
Can someone enlighten me?

Thanks in advance ,

Batoe
User avatar
Eran
DevNet Master
Posts: 3549
Joined: Fri Jan 18, 2008 12:36 am
Location: Israel, ME

Re: More mysql syntax error?

Post by Eran »

You can not use a WHERE clause with INSERT, it makes no sense.
User avatar
requinix
Spammer :|
Posts: 6617
Joined: Wed Oct 15, 2008 2:35 am
Location: WA, USA

Re: More mysql syntax error?

Post by requinix »

You're trying to do one of two things:
- Create a new row
- Update an existing row
Actually, it'd be more correct you're trying to do both. Which, by the way, you can't.

For the second option the query is

Code: Select all

UPDATE table SET field=value WHERE condition
Post Reply