我需要通过 PHP 更改表中的内容。这是那部分脚本。在第一个 if 语句中,它调用查询出了问题。怎么了?
if (!($query = $db->prepare('UPDATE Accounts SET firstname=:firstname, lastname=:lastname, age=:age, location=:location WHERE username=:username')) === false) {
exit('{"result": "something went wrong preparing the query"}');
}
if (!$query->execute(array('firstname' => $_POST['firstname'], ':lastname' => $_POST['lastname'], ':age' => $_POST['age'], ':location' => $_POST['location'], ':username' => $_POST['username']))) {
exit('{"result": "something went wrong executing query"}');
} else {
exit('{"result": "changed fields"}');
}
最佳答案
为什么不使用标准准备语句(例如 seen here ):
$query = 'SELECT * FROM my_table WHERE title = :title';
$stmt = $db->prepare($query);
$stmt->bindValue(':title', $myTitle);
$stmt->execute();
这样你就能更好地了解哪里出了问题......
关于php - 使用PHP和MySQL,需要更改表中的列。查询未准备。,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/26347564/