gpt4 book ai didi

php - PDO MYSQL 更新不工作

转载 作者:行者123 更新时间:2023-11-29 05:34:12 25 4
gpt4 key购买 nike

我在获取正确的 sql 查询以更新用户配置文件时遇到问题。我(基本上)使用相同的查询来插入数据并且它工作正常(只是没有 WHERE id=clientid 并且在执行数组中没有 clientid。下面的查询不会更新数据库中的任何数据。

我进行了测试并确保所有变量都已发布并且确实如此。作为旁注,此查询是否可以避免 sql 注入(inject)?

$conn = new PDO("mysql:host=$DB_HOST;dbname=$DB_DATABASE",$DB_USER,$DB_PASSWORD);

// Deal with the POST variables here...(excluded)

$sql = "UPDATE clients (firstname, lastname, origincountry, dob, gender, email, phone, address, postal, city, province, referred, notes)
VALUES (:firstname, :lastname, :origincountry, :dob, :gender, :email, :phone, :address, :postal, :city, :province, :referred, :notes)
WHERE id = :clientid" ;

$q = $conn->prepare($sql);

$q->execute(array(':firstname'=>$firstname,
':lastname'=>$lastname,
':origincountry'=>$origincountry,
':dob'=>$dob,
':gender'=>$gender,
':email'=>$email,
':phone'=>$phone,
':address'=>$address,
':postal'=>$postal,
':city'=>$city,
':province'=>$province,
':referred'=>$referred,
':notes'=>$notes,
':clientid'=>$clientid));

最佳答案

您的 SQL 无效。参见 UPDATE . (感谢@rambocoder 指出这一点)。

使用这个 SQL:

UPDATE clients SET firstname = :firstname, lastname = :lastname, origincountry = :origincountry, dob = :dob, gender = :gender, email = :email, phone = :phone, address = :address, postal = :postal, city = :city, province = :province, referred = :referred, notes = :notes
WHERE id = :clientid

关于php - PDO MYSQL 更新不工作,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/12134344/

25 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com