Warning: mysqli_stmt::bind_param(): Number of variables doesn't match number of parameters in prepared statement [duplicate]

拥有回忆 提交于 2021-02-05 12:36:36

问题


I receive the following error:

Warning: mysqli_stmt::bind_param(): Number of variables doesn't match number of parameters in prepared statement

I am having trouble binding and executing the prepare statement. The connection to the database is succesfully established and it does manage to insert it into the database with the initial value of ?

Below is the code:

// 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();

回答1:


Lose the quotes around ? and use 10 params instead of 11

Instead of this:

$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);

Try this:

$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);



回答2:


Your prepared query doesn't have any placeholders. You are inserting 10 literal ? characters into your database.

You need to lose the quotes around the ?s:

$insert = "INSERT INTO record_user (ip,country,address,stack,skills,employment_type,city_selection,landing_time,submission_time,time_spent)
    VALUES (?,?,?,?,?,?,?,?,?,?)";


来源:https://stackoverflow.com/questions/32911663/warning-mysqli-stmtbind-param-number-of-variables-doesnt-match-number-of

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!