//我想插入价值为i9-7820aa的$ product我知道bind_param可能是四种类型之一i - 整数d - 双精度 - 字符串b - BLOB 我得到了这个错误mysqli_stmt :: bind_param():变量数与预备语句中的参数数量不匹配
$product = 'i9-7820aa';
$name = mysqli_real_escape_string($connect, $_POST['nickname']);
$show = mysqli_real_escape_string($connect, $_POST['show']);
$stmt = $connect->prepare("INSERT INTO my (page) // insert in sql
VALUES('$product')");
$stmt->bind_param("sss", $product, $name, $show);
$stmt->execute();
答案 0 :(得分:2)
绑定时必须使用占位符。没有它们,你没有做任何事情
在这里,您绑定了三个变量。因此,您需要为每个占位符设置三个占位符,然后在bind_param
函数中添加变量。
有关详细信息,请查看此this
$product = 'i9-7820aa';
$name = $_POST['nickname'];// you do not need to escape anything
$show = $_POST['show'];
$stmt = $connect->prepare("INSERT INTO my (page) // insert in sql
VALUES(?,?,?)");//we add three placeholders
$stmt->bind_param("sss", $product, $name, $show);// s stands for string, i stands for int,
$stmt->execute(); // returns true/false