我收到以下错误:
Warning: mysqli_stmt::bind_param(): Number of variables doesn't match number of parameters in prepared statement
我在绑定和执行prepare语句时遇到麻烦。与数据库的连接成功建立,并设法将其插入数据库,初始值为?
代码如下:
// Set up the query
$insert = "INSERT INTO record_user (ip,country,address,stack,skills,employment_type,city_selection,landing_time,submission_time,time_spent)
VALUES ('?','?','?','?','?','?','?','?','?','?')";
// Prepare the statement
$insert = $con->prepare($insert);
// Bind the statement
$insert->bind_param("ssssssssss", $user_ip, $country, $location, $stack, $skills, $employment, $city, $landing_time, $submission_time, $time_spent);
// Execute the statement
$insert->execute();
// Close the statement connection
$insert->close();
// Close the database connection
$con->close();
去掉?
周围的引号,使用10个参数而不是11个
而不是:
$insert = "INSERT INTO record_user (ip,country,address,stack,skills,employment_type,city_selection,landing_time,submission_time,time_spent)
VALUES ('?','?','?','?','?','?','?','?','?','?')";
$insert = $con->prepare($insert);
$insert->bind_param("ssssssssss", $user_ip, $country, $location, $stack, $skills, $employment, $city, $landing_time, $submission_time, $time_spent);
试试这个:
$insert = "INSERT INTO record_user (ip,country,address,stack,skills,employment_type,city_selection,landing_time,submission_time,time_spent)
VALUES (?,?,?,?,?,?,?,?,?,?)";
$insert = $con->prepare($insert);
$insert->bind_param("ssssssssss", $user_ip, $country, $location, $stack, $skills, $employment, $city, $landing_time, $submission_time, $time_spent);
您准备的查询没有任何占位符。您正在向数据库中插入10个文字 ?
字符。
您需要去掉?
s周围的引号:
$insert = "INSERT INTO record_user (ip,country,address,stack,skills,employment_type,city_selection,landing_time,submission_time,time_spent)
VALUES (?,?,?,?,?,?,?,?,?,?)";