Page 1 of 1

More mysql syntax error?

Posted: Mon Nov 10, 2008 3:50 pm
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

Re: More mysql syntax error?

Posted: Mon Nov 10, 2008 4:05 pm
by Eran
You can not use a WHERE clause with INSERT, it makes no sense.

Re: More mysql syntax error?

Posted: Mon Nov 10, 2008 4:05 pm
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