Number of elements in type definition string doesn

2019-03-07 06:30发布

问题:

Please help me. I don't actually use PHP but I need to use in my Login/Register project.

$con = mysqli_connect("***", "***", "***", "***");

$name = $_POST["name"];
$username = $_POST["username"];
$password = $_POST["password"];
$statement = mysqli_prepare($con, "INSERT INTO user (name, username, password) VALUES (?, ?, ?)");
mysqli_stmt_bind_param($statement, "siss", $name, $username, $password);
mysqli_stmt_execute($statement);

$response = array();
$response["success"] = true;  

echo json_encode($response);

But it says

Warning: mysqli_stmt_bind_param() [function.mysqli-stmt-bind-param]: Number of elements in type definition string doesn't match number of bind variables in /home/a3598479/public_html/Register.php on line 8

How can I fix this?

回答1:

I think problem in following statement:

mysqli_stmt_bind_param($statement, "siss", $name, $username, $password);

You are passing siss which means it there should be 4 params with types string, integer, string and string which is wrong as you have only three parameters which are all string.

So the statement should be like this:

 mysqli_stmt_bind_param($statement, "sss", $name, $username, $password);


标签: php mysqli login