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(); }
- your
update
syntax wrong - 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
Post a Comment