Update query with PDO and MySQL

后端 未结 3 1784
既然无缘
既然无缘 2020-11-29 06:53

Im trying to write an update query with PDO only I cant get my code to execute?

try {
 $conn = new PDO(\"mysql:host=$hostdb; dbname=$namedb\", $userdb, $pass         


        
3条回答
  •  臣服心动
    2020-11-29 07:12

    1. Your UPDATE syntax is wrong
    2. You probably meant to update a row not all of them so you have to use WHERE clause to target your 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 
     WHERE `user_id` = :user_id -- you probably have some sort of id 
    

提交回复
热议问题