prepare($sth);$q->execute(array(' :location'=>$location,':id'=>$id));but I get this error"> Using PHP PDO prepared statements for update operations-PHP Chinese Network Q&A
Using PHP PDO prepared statements for update operations
P粉668019339
P粉668019339 2023-08-24 19:21:05
0
2
362

I'm trying to update my database using 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));

But I get this error

Fatal error: Uncaught exception 'PDOException' with message 'SQLSTATE[42000]: Syntax error or access violation: 1064 There is an error in your SQL syntax; check the Manual for the correct syntax to use near 'VALUES ('test') WHERE rpacks_id = ('2')' on line 1 of

P粉668019339
P粉668019339

reply all (2)
P粉315680565

change to:

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

    P粉248602298

    There is an error in yourupdatequery because you used theinsertquery syntax.

    The following is the correct query:

    $sql = "UPDATE rpacks SET rpacks_location = :location WHERE rpacks_id = :id"; $stmt = $conn->prepare($sql); $stmt->execute([':location'=>$location, ':id'=>$id]);

    refer to:http://dev.mysql.com/doc/refman/5.0/ en/update.html

      Latest Downloads
      More>
      Web Effects
      Website Source Code
      Website Materials
      Front End Template
      About us Disclaimer Sitemap
      php.cn:Public welfare online PHP training,Help PHP learners grow quickly!