PDOStatement::execute():SQLSTATE[HY093]:参数编号无效:绑定变量的数量与第27行的



你好!这里是堆栈溢出新手。我正在做这项任务,我被困在了这部分。我需要更新DB,但我得到了";无效的参数编号:绑定变量的数量与令牌的数量不匹配"错误我试着浏览了一下论坛,虽然我能找到一些有类似问题的人,但我仍然没有解决

这是我的代码:

<?php
// Get the product data
$category_id = filter_input(INPUT_POST, 'category_id', FILTER_VALIDATE_INT);
$code = filter_input(INPUT_POST, 'code');
$name = filter_input(INPUT_POST, 'name');
$price = filter_input(INPUT_POST, 'price', FILTER_VALIDATE_FLOAT);
$product_id = filter_input(INPUT_POST, 'productID');
// Validate inputs
if ($category_id == null || $category_id == false ||
$code == null || $name == null || $price == null || $price == false) {
$error = "Invalid product data. Check all fields and try again.";
include('error.php');
} else {
require_once('database.php');
// Add the product to the database  
$query = 'UPDATE products SET categoryID = :category_id,  productCode = :code, productName = :name, listPrice = :price WHERE productID = :product_id';

// $db->exec($query);

$statement = $db->prepare($query);
$statement->bindValue(':category_id', $category_id, PDO::PARAM_INT);
$statement->bindValue(':code', $code, PDO::PARAM_INT);
$statement->bindValue(':name', $name, PDO::PARAM_INT);
$statement->bindValue(':price', $price, PDO::PARAM_INT); //line 27
$statement->execute();
$statement->closeCursor();
// Display the Product List page
include('index.php');
}
?>

在SQL中,您在where子句中使用了一个参数,":product_id";,但你似乎忘记绑定了。添加bind语句。

最新更新