php - Update query with PDO and MySQL -


im trying write update query pdo cant code execute?

try {  $conn = new pdo("mysql:host=$hostdb; dbname=$namedb", $userdb, $passdb); $conn->exec("set character set utf8");      // sets encoding utf-8 $conn->setattribute(pdo::attr_errmode, pdo::errmode_exception);   $sql = "update `access_users`          (`contact_first_name`,`contact_surname`,`contact_email`,`telephone`)        values (:firstname, :surname, :telephone, :email);       ";     $statement = $conn->prepare($sql);  $statement->bindvalue(":firstname", $firstname);  $statement->bindvalue(":surname", $surname);  $statement->bindvalue(":telephone", $telephone);  $statement->bindvalue(":email", $email);  $count = $statement->execute();    $conn = null;        // disconnect } catch(pdoexception $e) {   echo $e->getmessage(); } 

  1. your update syntax wrong
  2. you meant update row not of them have use where clause target specific row

change

update `access_users`          (`contact_first_name`,`contact_surname`,`contact_email`,`telephone`)        values (:firstname, :surname, :telephone, :email) 

to

update `access_users`       set `contact_first_name` = :firstname,        `contact_surname` = :surname,        `contact_email` = :email,        `telephone` = :telephone   `user_id` = :user_id -- have sort of id  

Comments

Popular posts from this blog

Detect support for Shoutcast ICY MP3 without navigator.userAgent in Firefox? -

web - SVG not rendering properly in Firefox -

java - JavaFX 2 slider labelFormatter not being used -