我认为我的代码没有任何问题,但我仍然在我的代码中收到这个根本没有意义的错误。
警告:mysqli_stmt::bind_param():变量数与第 131 行预准备语句中的参数数不匹配
这是我的完整代码:
$stmt = $db_conx->prepare("SELECT id, product_name FROM yt ORDER by id");
if ($stmt) {
$product_list = "";
$stmt->bind_param("is", $id, $product_name);
if ( ! $stmt->execute() ) {
die ( $stmt->error );
}
$stmt->bind_result($id, $product_name);
$stmt->store_result();
while ($stmt->fetch()) {
$value[] = array('id'=>$id, 'product_name'=>$product_name);
$product_list .= "<li class='mix ".$product_name."' data-name='".$product_name."'><a href='../product_images/" . $id . "Image1.jpg'>
<img src='../product_images/" . $id . "Image1.jpg'></a>
<h4>".$product_name."</h4>
<br>
</li>
<div style='width:120px;'><a href='edit.php?edit=$id'>Edit this product</a></div>
<br>
<div style='width:120px;'><a href='products.php?delete=$id'>Delete this product</a></div>";
$files = glob('../cache/*'); // get all file names
foreach ($files as $file) { // iterate files
if (is_file($file)) {
unlink($file); // delete file
}
}
}
mysqli_stmt_close($stmt);
这就是第 131 行的内容:
$stmt->bind_param("is", $id, $product_name);
我错过了什么吗?
您尝试将 2 个参数绑定到没有任何参数的查询:
$stmt = $db_conx->prepare("SELECT id, product_name FROM yt ORDER by id");
$stmt->bind_param("is", $id, $product_name);
仅当为参数定义占位符时,才能绑定参数,如下所示:
$stmt = $db_conx->prepare("SELECT id, product_name FROM where id = ? or product_name = ?");
$stmt->bind_param("is", $id, $product_name);
?
表示可以将参数绑定到的占位符。
我得到了同样的错误,但我的问题只是,我使用了厚,我有一段时间没有注意到这一点。Ofc,在这种情况下是我的?是一个字符串而不是一个变量...,我希望它能帮助某人,所以使用这个:
选择 * 其中 langCode = ?
取而代之的是:
选择 * 其中 langCode = '?'
您正在绑定 SQL 语句中不存在的参数"is"编辑:而且你也没有任何"?"占位符
msqli_stmt::bind_param