我有这个PDO查询工作正常...
$stmt = $pdo->prepare("UPDATE pools SET poolname = :poolname, pooldescription = :pooldescription");
$stmt->execute([':poolname' => $poolname, ':pooldescription' => $pooldescription]);
redirect_to('/my-pools');
然后我意识到我遗漏了WHERE声明(是的,非常重要的哈哈),所以我在下面添加了它。
$stmt = $pdo->prepare("UPDATE pools SET poolname = :poolname, pooldescription = :pooldescription WHERE poolid = :poolid");
$stmt->execute([':poolname' => $poolname, ':pooldescription' => $pooldescription, ':poolid' => $poolid]);
redirect_to('/my-pools');
但是,这会导致以下错误:
Fatal error: Uncaught PDOException: SQLSTATE[HY093]: Invalid parameter number: parameter was not defined in /home/mysite/public_html/mypage.php:65 Stack trace: #0 /home/mysite/public_html/mypage.php(65): PDOStatement->execute(Array) #1 {main} thrown in /home/mysite/public_html/mypage.php on line 65
我是否错误地添加了poolid
占位符和/或在执行数组中写错了什么?
看起来非常简单,所以我必须遗漏一些超级显眼的东西。
更新:这是在页面前面设置$ poolid的方式
if (isset($_SESSION['poolid'])) {
$poolid = $_SESSION['poolid'];
} else {
redirect_to('/');
}