I am facing problem while fetching data from database using prepared statement

问题: 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

  • 发表于 2019-01-22 17:23
  • 阅读 ( 207 )
  • 分类:网络文章

条评论

请先 登录 后评论
不写代码的码农
小编

篇文章

作家榜 »

  1. 小编 文章
返回顶部
部分文章转自于网络,若有侵权请联系我们删除