Reputation: 1959
I'm trying to build an update query but I keep getting the following 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 '='Damien',
last_name
='Surname', whereid
='49'' at line 2
My PHP is as follows:
if($get['cmd'] == 'sname')
{
mysql_query("update users
`first_name`='$get[first_name]',
`last_name`='$get[last_name]',
where `id`='$get[id]'") or die(mysql_error());
//header("Location: $ret");
echo "changes done";
exit();
}
and HTML as follows
<input name="doSave" type="button" id="doSave" value="Save" onclick='$.get("dos.php",{ cmd: "sname",first_name:$("input#first_name").val(),last_name:$("input#last_name").val(),id: "<?php echo $row_settings['id']; ?>" } ,function(data){ $("#msg").html(data); });'>
Can anyone see what's wrong in my code that will be giving me this error?
Upvotes: 0
Views: 100
Reputation: 496
If i am not wrong SET keyword is required and the extra comma is to be removed..correct me if I am wrong...
if($get['cmd'] == 'sname')
{
mysql_query("update users SET
first_name ='$get[first_name]',
last_name ='$get[last_name]'
where id ='$get[id]'") or die(mysql_error());
//header("Location: $ret");
echo "changes done";
exit();
}
Upvotes: 4
Reputation:
You have a comma
after the below statement that is not required.
`last_name`='$get[last_name]',
It should be as stated below. Note that the comma
has been removed from the end of this line.
`last_name`='$get[last_name]'
Upvotes: 2