I've done plenty of MySQLi work on at least a dozen sites I've designed for myself, but I just can't seem to figure this one out. I am sure I'll be kicking myself for the time I've wasted today.
Here's what's in my database connection file:
if(!isset($dbc))
{
DEFINE('DB_USER', '*My User Name*');
DEFINE('DB_PASSWORD', '*My Pass Word*');
DEFINE('DB_HOST', '*Correct Host Name*');
DEFINE('DB_NAME', '*Correct DB Name*');
if(!$dbc = @mysqli_connect(DB_HOST, DB_USER, DB_PASSWORD, DB_NAME))
{
$subject = 'MySQLi Error - $now";
$message = "MySQLi_Connect.php error ' . mysql_error($dbc);
mail('*My Main Email*', $subject, $message, 'From *My Other Email*');
die('Something has gone horribly wrong');
}
}
Here's the code giving me the trouble:
$query="INSERT INTO
temp_users
(user_name, password, email, key, timestamp)
VALUES
(?,?,?,?,?)";
$stmt = mysqli_prepare($dbc, $query);
mysqli_stmt_bind_param($stmt, "ssssi", $user_name, $password, $email, $email_hash, $now);
mysqli_stmt_execute($stmt);
if(mysqli_stmt_affected_rows($result) == 1)
{
$test = "Passed";
}
else
{
$test = "Failed";
}
I know all the variables in mysqli_stmt_bind_param are properly populated, as I have them echo out at the bottom of the page just to be certain. I know the connection to the DB is working properly, as I have other mysqli queries on the page that work properly, just not this one. None of the other queries are Insert queries, though. I receive the following error messages:
Warning: mysqli_stmt_bind_param() expects parameter 1 to be mysqli_stmt, boolean given in /full/path/to/script.php on line 73
Warning: mysqli_stmt_execute() expects parameter 1 to be mysqli_stmt, boolean given in /full/path/to/script.php on line 74
Warning: mysqli_stmt_affected_rows() expects parameter 1 to be mysqli_stmt, null given in /full/path/to/script.php on line 76