This question already has an answer here:
I am using this code and i try to run it but it shows this error and try to fix it but i don't know how? Can anyone help me? :
Warning: mysqli_stmt_bind_param() expects parameter 1 to be mysqli_stmt, boolean given in /home/u330779411/public_html/Register.php on line 10
Warning: mysqli_stmt_execute() expects parameter 1 to be mysqli_stmt, boolean given in /home/u330779411/public_html/Register.php on line 11
Warning: mysqli_stmt_close() expects parameter 1 to be mysqli_stmt, boolean given in /home/u330779411/public_html/Register.php on line 13
Here is my code:
$name = $_POST['name'];
$matric_number = $_POST['matric_number'];
$username = $_POST['username'];
$password = $_POST['password'];
$statement = mysqli_prepare($con, "INSERT INTO Users (name, matric_number, username, password) VALUES (?, ?, ?, ?)");
mysqli_stmt_bind_param($statement, "siss", $name, $matric_number, $username, $password);
mysqli_stmt_execute($statement);
mysqli_stmt_close($statement);
mysqli_close($con);
Is it
</div>
According to the PHP Docs:
mysqli_prepare() returns a statement object or FALSE if an error occurred.
Since your warning states that a boolean was given, it is likely that an error occurred. I would suggest doing var_dump($statement)
as @Dagon suggested to check if $statement
is set to false
.
You might also want to check $con
. I am assuming that you omitted that part and that you initialized it properly earlier in the code, but make sure you are checking for mysqli_connect_error()
as well.