I want to execute twor prepared statements in one php script. If it is only one it works fine, but as soon as I want to execute two or more ot does not work any more. I think it is some basic behaviour I do not know about prepared statements, but I could not find anything on my own, maybe I searched for the wrong problem. anyway, this is my code which does not enter the second if block
$query_checkIfUserMailExists = "SELECT email FROM user WHERE email = ?";
if($stmt = mysqli_prepare($connection, $query_checkIfUserMailExists))
{
mysqli_stmt_bind_param($stmt, "s", $_POST["addUser_email"]);
mysqli_stmt_execute($stmt);
$result = mysqli_stmt_get_result($stmt);
mysqli_stmt_close($stmt);
}
This works, but a few lines later these lines do not work
$query_addUser = "INSERT INTO user (firstname, surname, [...]) VALUES (?, ?, [...])";
if($stmt = mysqli_prepare($connection, $query_addUser))
{
echo "I am never printed";
mysqli_stmt_bind_param($stmt, "sssssssssss", $addUser_firstName, $addUser_surName, [...]);
$resultAddUser = mysqli_stmt_execute($stmt);
mysqli_stmt_close($stmt);
}
I thought that I need to close a stmt with mysqli_stmt_close, but apparently that does not work. I know, that the second id block is not entered, because I do not read "I am never entered" if I execute this code. I also tried naming the seond $stmt different ($stmt1), but that did not help either.
John