I'm trying to update my database with the following query:
$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
There is a mistake in your update
query because you used insert
query syntax.
Here is the correct query:
$sth = "UPDATE rpacks SET rpacks_location = :location WHERE rpacks_id = :id";
Reference: http://dev.mysql.com/doc/refman/5.0/en/update.html
改成:
$sth = "UPDATE rpacks SET rpacks_location = :location WHERE rpacks_id = :id";
The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.