Good day, I'm not really familiar with PHP and i get this error when i try to execute my query.
Warning:
Warning: mysqli_stmt::bind_param(): Number of variables doesn't match number of parameters in prepared statement in /Users/site/userpanel.php on line 10
Code:
$query="SELECT SUM(gebruiker_id) AS totalitems FROM inventory WHERE gebruiker_id = 1";
$stmt = $db->prepare($query);
$stmt->bind_param("s", $items);
$stmt->execute();
$result = $stmt->bind_result($col1);
Thanks in advance!
You have to use a placeholder like this:
$query="SELECT SUM(gebruiker_id) AS totalitems FROM inventory WHERE gebruiker_id = ?";
$stmt = $db->prepare($query);
$stmt->bind_param("s", $items);
$stmt->execute();
$result = $stmt->bind_result($col1);
Sometimes you don't need to bind:
$query="SELECT SUM(gebruiker_id) AS totalitems FROM inventory WHERE gebruiker_id = 1";
$stmt = $db->prepare($query);
//$stmt->bind_param("s", $items);
$stmt->execute();
$result = $stmt->bind_result($col1);
or
$query="SELECT SUM(gebruiker_id) AS totalitems FROM inventory WHERE gebruiker_id = 1";
$stmt = $db->query($query);
$result = $stmt->bind_result($col1);
But if you were trying to bind $items
to gebruiker_id
then follow @rizier123
answer.
The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.