我无法插入数据条目。我花了几个小时,查看各种教程和示例代码,但我无法弄清楚为什么以下内容不起作用:
$data1 = 0;
$data2 = "pumpkin";
$data3 = "cake";
$data4 = "orange";
$data5 = "sweet";
$stmt = $mysqli->stmt_init();
// Here I have a few SELECT queries that checks if $data2 and/or $data3 is already taken
$query = "INSERT INTO ". $mytable . " SET data1=?, data2=?, data3=?, data4=?, data5=?";
if ($stmt->prepare($query)) {
$stmt->bind_param("issss", $data1, $data2, $data3, $data4, $data5);
$stmt->execute() or trigger_error($mysqli->error); // added per Your Common Sense's suggestion
//$stmt->bind_result($data1, $data2, $data3, $data4, $data5);
$stmt->close();
$mysqli->close();
} else {
echo $mysqli->error; // edited per Yogesh Suthar's suggestion
$stmt->close();
$mysqli->close();
}
我在网上遇到错误$stmt->bind_result
。
警告:mysqli_stmt::bind_result():绑定变量的数量与准备好的语句中的字段数量不匹配
我究竟做错了什么?
我在 $db_user、$db_password、$db_dbname 上正确定义了以下内容:
$mysqli = new mysqli('localhost', $db_user, $db_password, $db_dbname);