美好的一天,我对PHP并不熟悉,当我尝试执行查询时出现此错误。
警告:
警告:mysqli_stmt :: bind_param():变量数与预准备语句中的参数数量不匹配 第10行/Users/site/userpanel.php
代码:
$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);
提前致谢!
答案 0 :(得分:3)
您必须使用这样的占位符:
$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);
答案 1 :(得分:1)
有时您不需要绑定:
$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);
或
$query="SELECT SUM(gebruiker_id) AS totalitems FROM inventory WHERE gebruiker_id = 1";
$stmt = $db->query($query);
$result = $stmt->bind_result($col1);
但如果您尝试将$items
绑定到gebruiker_id
,请按@rizier123
回答。