Mysqli throws "Warning: mysqli_stmt_bind_param() expects parameter 1 to be mysqli_stmt, boolean given" [duplicate]
Solution 1:
Add more error handling.
When the connection fails, mysqli_connect_error() can tell you more details.
When preparing the statement fails mysqli_error() has more infos about the error.
When executing the statement fails, ask mysqli_stmt_error(). And so on and on...
Any time a function/method of the mysqli module returns false to indicate an error, a) handle that error and b) decide whether it makes sense or not to continue. E.g. it doesn't make sense to continue with database operations when the connection failed. But it may make sense to continue inserting data when just one insertion failed (may make sense, may not).
For testing you can use something like this:
$connection = mysqli_connect(...);
if ( !$connection ) {
die( 'connect error: '.mysqli_connect_error() );
}
$query = "INSERT INTO entries (name, dob, school, postcode, date) VALUES (?,?,?,?,?)";
$stmt1 = mysqli_prepare($connection, $query);
if ( !$stmt1 ) {
die('mysqli error: '.mysqli_error($connection);
}
mysqli_stmt_bind_param($stmt1, 'sssss',$name,$dob,$school,$postcode,$date);
if ( !mysqli_execute($stmt1) ) {
die( 'stmt error: '.mysqli_stmt_error($stmt1) );
}
...
For a real production environment this approach is to talkative and dies to easily ;-)
Solution 2:
The problem comes from mysqli_prepare()
, which in your case returns false
, hence the 'boolean given' error. As your query seems ok, the error must be in $connection
. Are you sure that the connection works and is defined?
The connection should be defined as something like this:
$connection = mysqli_connect("localhost", "my_user", "my_password", "world");
If the connection is properly defined, you can use echo mysqli_connect_error()
to see if something went wrong. You said that the code works on another site, so perhaps you forgot to change the credentials or host?