I wonder if anyone can help spot what I've done wrong. I keep getting the following error messages when I submit a comment on the post_message.php form:
Warning: mysqli_stmt_bind_param() expects parameter 1 to be mysqli_stmt, boolean given in D:\xampp\htdocs\PHPMYSQL\Chapter 12\post_message.php on line 25
Warning: mysqli_stmt_execute() expects parameter 1 to be mysqli_stmt, boolean given in D:\xampp\htdocs\PHPMYSQL\Chapter 12\post_message.php on line 35
Warning: mysqli_stmt_affected_rows() expects parameter 1 to be mysqli_stmt, boolean given in D:\xampp\htdocs\PHPMYSQL\Chapter 12\post_message.php on line 38
Your message could not be posted.
Warning: mysqli_stmt_error() expects parameter 1 to be mysqli_stmt, boolean given in D:\xampp\htdocs\PHPMYSQL\Chapter 12\post_message.php on line 45
Warning: mysqli_stmt_close() expects parameter 1 to be mysqli_stmt, boolean given in D:\xampp\htdocs\PHPMYSQL\Chapter 12\post_message.php on line 50
All these warnings refer to lines where I refer to the $stmt. I have written the script twice but get same result. I've compared it line for line with the script from the book and the downloaded post_message.php file. I can't find the error.
My code is:
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
<html xmlns="http://www.w3.org/1999/xhtml">
<head>
<meta http-equiv="Content-Type" content="text/html; charset=utf-8" />
<title>Post a Message</title>
</head>
<body>
<?php #Script 12.4 -post_message.php
if(isset($_POST['submitted'])){
//validate the data omitted!
//connect to database:
$dbc = mysqli_connect('localhost','username','password','forum'); //substituted my username and password
//make the query:
$q = 'INSERT INTO messages(forum_id, parent_id, user_id, subject, body, date_entered) VALUES(?,?,?,?,?, NOW())';
//prepare the statement:
$stmt = mysqli_prepare($dbc, $q);
//bind the variables:
mysqli_stmt_bind_param($stmt, 'iiiss', $forum_id, $parent_id, $user_id, $subject, $body);
//assign the values to the variables:
$forum_id = (int)$_POST['forum_id'];
$parent_id = (int)$_POST['parent_id'];
$user_id = 3;
$subject = strip_tags($_POST['subject']);
$body = strip_tags($_POST['body']);
//execute the query:
mysqli_stmt_execute($stmt);
//Print a message based on the result:
if(mysqli_stmt_affected_rows($stmt)==1){
echo '<p>Your message has been posted.</p>';
}else{
echo '<p style="font-weight:bold; color:#c00">Your message could not be posted.</p>';
echo '<p>'.mysqli_stmt_error($stmt).'</p>';
}
//close the statement
mysqli_stmt_close($stmt);
//close the connection:
mysqli_close($dbc);
}//end of submission IF
//display form
?>
<form action="post_message.php" method="post">
<fieldset>
<legend>Post a message:</legend>
<p><b>Subject</b>:<input name="subject" type="text" size="30" maxlength="100"/></p>
<p><b>Body</b>:<textarea name="body" rows="3" cols="40"></textarea>
</fieldset>
<div align="center"><input type="submit" name="submit" value="Submit"/></div>
<input type="hidden" name="submitted" value="TRUE"/>
<input type="hidden" name="forum_id" value="1"/>
<input type="hidden" name="parent_id" value="0"/>
</form>
</body>
</body>
</html>
I'm using Vista home basic,Dreamweaver cs4, xampp v3.02 with Apache 2.0 Handler and phpmyadmin version 3.4.5 . phpinfo gives the configuration path for php.ini as C:\Windows and Loaded configuration file as D:xampp\php\php.ini.
Thanks in advance for any help.










