Jump to content
Larry Ullman's Book Forums

majorwitty

Members
  • Posts

    5
  • Joined

  • Last visited

majorwitty's Achievements

Newbie

Newbie (1/14)

0

Reputation

  1. Thanks for your quick response, I figured it out then came back to delete post and saw you answered. I'm missing the '_' in $_SESSION['lid'] I know a lot more about debugging now which is a good thing. Hey, since you're reading this can you comment on the errata page for the book? I posted an errata and haven't heard anything.
  2. Can someone echo out their $q variable from Chapter 17 Script 17.4 and show me the output? My query is failing as the result of $r is FALSE so I'm getting a Warning: mysqli_num_rows() expects parameter 1 to be mysqli_result when I test forum.php When I echo out the $q variable ( I used echo '<p>The query $q is ' . $q . '</p><br /><br />'; on line 21) I get these results in web browser: The query $q is SELECT t.thread_id, t.subject, username, COUNT(post_id) - 1 AS responses, MAX(DATE_FORMAT(CONVERT_TZ(p.posted_on, 'UTC', 'America/New_York'), '%e-%b-%y %l:%i %p')) AS last, MIN(DATE_FORMAT(CONVERT_TZ(p.posted_on, 'UTC', 'America/New_York'),'%e-%b-%y %l:%i %p')) AS first FROM threads AS t INNER JOIN posts AS p USING (thread_id) INNER JOIN users AS u ON t.user_id = u.user_id WHERE t.lang_id = GROUP BY (p.thread_id) ORDER BY last DESC I'm wondering why {$SESSION['lid']} is missing from the output. Here is my line 19 code (matches the book): $q = "SELECT t.thread_id, t.subject, username, COUNT(post_id) - 1 AS responses, MAX(DATE_FORMAT($last, '%e-%b-%y %l:%i %p')) AS last, MIN(DATE_FORMAT($first, '%e-%b-%y %l:%i %p')) AS first FROM threads AS t INNER JOIN posts AS p USING (thread_id) INNER JOIN users AS u ON t.user_id = u.user_id WHERE t.lang_id = {$SESSION['lid']} GROUP BY (p.thread_id) ORDER BY last DESC";
  3. Your suggestions have helped me out, thank you! When I looked at messages table I noticed the db name was different. My mysqli_connect.php file had incorrect DBNAME value. Up to Chapter 13 in book I've created three DBs. My mysqli_connect was pointing to user registration versus forum DB. Once I fixed mysqli_connect.php (I now use mysqli_connect_[dbname].php files) I continued to get same errors. I then changed the code to be identical to the book: // 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); // Assign the values to variables: $forum_id = (int) $_POST['forum_id']; $parent_id = (int) $_POST['parent_id']; $user_id = 3; // The user_id value would normally come from the session. $subject = strip_tags($_POST['subject']); $body = strip_tags($_POST['body']); // Bind the variables: mysqli_stmt_bind_param($stmt, 'iiiss', $forum_id, $parent_id, $user_id, $subject, $body); Again, thanks for the assistance!
  4. Thanks for suggestions. I still encounter an issue. Here is updated code: if ($_SERVER['REQUEST_METHOD'] == 'POST') { // Validate the data (omitted)! // Connect to database: require ('../../../../phpfiles/mysqli_connect.php'); // Check db connection if (!$dbc) { die('Connect Error (' . mysqli_connect_errno() . ') ' . mysqli_connect_error()); } echo 'Success... ' . mysqli_get_host_info($dbc) . "\n"; // Make the query: $q = 'INSERT INTO messages (forum_id, parent_id, user_id, subject, body, date_entered=NOW()) VALUES (?, ?, ?, ?, ?)'; // Prepare the statement: $stmt = mysqli_prepare($dbc, $q); // Assign the values to variables: $forum_id = (int) $_POST['forum_id']; $parent_id = (int) $_POST['parent_id']; $user_id = 3; // The user_id value would normally come from the session. $subject = strip_tags($_POST['subject']); $body = strip_tags($_POST['body']); // Bind the variables: mysqli_stmt_bind_param($stmt, 'iiiss', $forum_id, $parent_id, $user_id, $subject, $body); // Execute the query: mysqli_stmt_execute($stmt); // Print a message based upon 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); Here is the full output from web browser accessing post_message.php: Success... practicedb.domainname.info via TCP/IP Warning: mysqli_stmt_bind_param() expects parameter 1 to be mysqli_stmt, boolean given in /[ABSOLUTEPATH]/post_message.php on line 39 Warning: mysqli_stmt_execute() expects parameter 1 to be mysqli_stmt, boolean given in /[ABSOLUTEPATH]/post_message.php on line 42 Warning: mysqli_stmt_affected_rows() expects parameter 1 to be mysqli_stmt, boolean given in /[ABSOLUTEPATH]/post_message.php on line 45 Your message could not be posted. Warning: mysqli_stmt_error() expects parameter 1 to be mysqli_stmt, boolean given in /[ABSOLUTEPATH]/post_message.php on line 49 Warning: mysqli_stmt_close() expects parameter 1 to be mysqli_stmt, boolean given in /[ABSOLUTEPATH]/post_message.php on line 53
  5. Hi, I receive errors while running post_message.php. Warning: mysqli_stmt_bind_param() expects parameter 1 to be mysqli_stmt, boolean given in /ABSOLUTEPATH/post_message.php on line 24 Below is my code, only difference between book and mine is connecting to database portion. I removed that and put appropriate data and still same error. Anyone able to help? I think $stmt has wrong value but I'm not sure how to confirm the appropriate value. if ($_SERVER['REQUEST_METHOD'] == 'POST') { // Connect to database: require ('../../../../phpfiles/mysqli_connect.php'); // 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 variables: $forum_id = (int) $_POST['forum_id']; $parent_id = (int) $_POST['parent_id']; $user_id = 3; // The user_id value would normally come from the session. $subject = strip_tags($_POST['subject']); $body = strip_tags($_POST['body']); // Execute the query: mysqli_stmt_execute($stmt); // Print a message based upon 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 forum submission phpinfo() shows: PHP Version 5.3.13 mysqli Mysqli Support enabled Client API library version 5.1.63 Active Persistent Links 0 Inactive Persistent Links 0 Active Links 0 Client API header version 5.1.61 MYSQLI_SOCKET /No-MySQL-hostname-was-specified
×
×
  • Create New...