Roy
Roy

Reputation: 1

Simple Where Clause has syntax error

$entries = "INSERT INTO allowances (totalGrossPay) VALUES ('".$totalGrossPay."') WHERE (allowances.SSN = '".$SSN."')";
mysql_query ($entries) or die (mysql_error());

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 (allowances.SSN = '300497654')'

Upvotes: 0

Views: 87

Answers (3)

0xCAFEBABE
0xCAFEBABE

Reputation: 5666

And if you want to update a possibly existing record and otherwise insert the record, you can use the ON DUPLICATE KEY phrase of the INSERT statement to specify what happens if the record already exists.

Upvotes: 0

onteria_
onteria_

Reputation: 70487

Just do an update:

$entries = "UPDATE `allowances` SET `totalGrossPay` = '{$totalGrossPay}' WHERE `SSN` = '{$SSN}'";
mysql_query ($entries) or die (mysql_error());

Upvotes: 2

Daniel Hilgarth
Daniel Hilgarth

Reputation: 174299

What do you think should happen? INSERT is unconditional, no WHERE clause is required or even allowed.
What you really want is an UPDATE.

Upvotes: 2

Related Questions