2013-04-14 136 views
1

我想用下面的查询来更新我的数据库:PHP PDO更新准备的语句

$sth = "UPDATE rpacks SET rpacks_location VALUES (:location) WHERE rpacks_id = (:id)"; 
$q = $conn->prepare($sth); 
$q->execute(array(':location'=>$location, ':id'=>$id)); 

但我发现了这个错误

Fatal error: Uncaught exception 'PDOException' with message '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 'VALUES ('test') WHERE rpacks_id = ('2')' at line 1' in

+0

你的SQL语句,你应该使用SET字段=错误(:东西)没有值 – ahmad

回答

1

更改为:

$sth = "UPDATE rpacks SET rpacks_location = :location WHERE rpacks_id = :id";