Reputation: 113
I there any problem on my code??? If its ok then why i am always get this error
PDOException: SQLSTATE[42000]: Syntax error or access violation: 1064 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 'add = 'Myaddress' WHERE id = '' at line 7 in C:****\class\class.admin.php on line 160
Here is my Code:
function EditClient($uname,$email,$pname,$cname,$mob,$add,$cid)
{
$query = $this->dbh->prepare("
UPDATE client SET
uname = :username,
email = :email,
pname = :pname,
cname = :cname,
mob = :mob,
add = :addr
WHERE id = :id ");
$query->execute(array(
':username' => $uname,
':email' => $email,
':pname' => $pname,
':cname' => $cname,
':mob' => $mob,
':addr' => $add,
':id' => $cid
)); //here is the line 160
return $query->rowCount();
}
Where the value of $cid is "Myaddress"
Upvotes: 0
Views: 46
Reputation: 18601
In mySql add
is reserve word so you need to change
add = :addr
to
`add` = :addr
add back-tick on add
keyword as mentioned above.
Check Manual for Reserve word in mysql.
Upvotes: 2
Reputation: 44874
The error is caused by using a reserved word ADD
add = :addr
You need to back-tick it
`add` = :addr
http://dev.mysql.com/doc/refman/5.0/en/reserved-words.html
Upvotes: 2