问题:
My DB Name is 'cart'. Table Name is 'products'. row are 'id', 'name', 'image', 'price'.
I am getting this error.
Warning: mysqli_stmt_bind_param(): Number of variables...
可以将文章内容翻译成中文,广告屏蔽插件会导致该功能失效:
问题:
My DB Name is 'cart'. Table Name is 'products'. row are 'id', 'name', 'image', 'price'.
I am getting this error.
Warning: mysqli_stmt_bind_param(): Number of variables doesn't match number of parameters in prepared statement in E:xammphtdocscartcart.php on line 9
Here is the screenshot
Here is the Code
<?php
$connect = mysqli_connect('localhost', 'root', '', 'cart');
$query = "SELECT * FROM `products`";
$stmt = mysqli_prepare($connect, $query);
if($stmt){
mysqli_stmt_bind_param($stmt, 'issi', $id, $name, $image, $price);
mysqli_stmt_bind_result($stmt, $id, $name, $image, $price);
mysqli_stmt_execute($stmt);
while(mysqli_stmt_fetch($stmt)){
echo "<pre>";
echo $id;
echo "</pre>";
}
}
Can anyone help?
回答1:
First of all, please dont't use "Select *", always select your columns instead.
uncomment the following line:
mysqli_stmt_bind_param($stmt, 'issi', $id, $name, $image, $price);
You don't need this for binding params in your result.
If you would have any params in your SELECT Statement that you want to bind, you can use mysqli_stmt_bind_param(....), but here it's not possible so you get this error.
More information here: http://php.net/manual/de/mysqli-stmt.bind-result.php
回答2:
as i see, you are not using any bound parameters in your query, like "SELECT * FROM product WHERE price = ? AND id = ?"
http://php.net/manual/de/mysqli.prepare.php