aba Posted October 13, 2013 Share Posted October 13, 2013 I'm new to Programing and it very frustrating each time I run the Chapter 15 Script - I keep getting these errors: 1. Warning: mysqli_num_rows() expects parameter 1 to be mysqli_result, boolean given in C:\wamp\www\phpmyql3_scripts\ch15\html\includes\header.html on line 37 2. Warning: mysqli_fetch_array() expects parameter 1 to be mysqli_result, boolean given in C:\wamp\www\phpmyql3_scripts\ch15\html\includes\header.html on line 47 3. Warning: mysqli_free_result() expects parameter 1 to be mysqli_result, boolean given in C:\wamp\www\phpmyql3_scripts\ch15\html\includes\header.html on line 50 Below is the script for the hearder.html file. I'd be very grateful if some1 would help me solve this problem - it's a pain on the neck <?php # Script 15.1 - header.html/* This script... * - starts the HTML template. * - indicates the encoding using header(). * - starts the session. * - gets the language-specific words from the database. * - lists the available languages. */ // Indicate the encoding:header ('Content-Type: text/html; charset=UTF-8'); // Start the session:session_start(); // For testing purposes:$_SESSION['user_id'] = 1;$_SESSION['user_tz'] = 'America/New_York';//$_SESSION = array(); // Need the database connection:require_once('../mysqli_connect.php'); // The language ID is stored in the session.// Check for a new language ID...if (isset($_GET['lid']) && is_numeric($_GET['lid'])) { $_SESSION['lid'] = (int) $_GET['lid'];} elseif (!isset($_SESSION['lid'])) { $_SESSION['lid'] = 1; // Default.} // Get the words for this language.$words = FALSE; // Flag variable.if ($_SESSION['lid'] > 0) { $q = "SELECT * FROM words WHERE lang_id = {$_SESSION['lid']}"; $r = mysqli_query($dbc, $q); if (mysqli_num_rows($r) == 1) { $words = mysqli_result_array($r, MYSQLI_ASSOC); }} // If we still don't have the words, get the default language:if (!$words) { $_SESSION['lid'] = 1; // Default. $q = "SELECT * FROM words WHERE lang_id = {$_SESSION['lid']}"; $r = mysqli_query($dbc, $q); $words = mysqli_fetch_array($r, MYSQLI_ASSOC);} mysqli_free_result($r);?><!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" xml:lang="en" lang="en"><head> <meta http-equiv="content-type" content="text/html; charset=utf-8" /> <title><?php echo $words['title']; ?></title> <style type="text/css" media="screen"> body { background-color: #ffffff; } .content { background-color: #f5f5f5; padding-top: 10px; padding-right: 10px; padding-bottom: 10px; padding-left: 10px; margin-top: 10px; margin-right: 10px; margin-bottom: 10px; margin-left: 10px; } a.navlink:link { color: #003366; text-decoration: none; } a.navlink:visited { color: #003366; text-decoration: none; } a.navlink:hover { color: #cccccc; text-decoration: none; } .title { font-size: 24px; font-weight: normal; color: #ffffff; margin-top: 5px; margin-bottom: 5px; margin-left: 20px; padding-top: 5px; padding-bottom: 5px; padding-left: 20px; } </style></head><body> <table width="90%" border="0" cellspacing="10" cellpadding="0" align="center"> <tr> <td colspan="2" bgcolor="#003366" align="center"><p class="title"><?php echo $words['title']; ?></p></td> </tr> <tr> <td valign="top" nowrap="nowrap" width="10%"><b><?php // Display links: // Default links:echo '<a href="index.php" class="navlink">' . $words['home'] . '</a><br /><a href="forum.php" class="navlink">' . $words['forum_home'] . '</a><br />'; // Display links based upon login status:if (isset($_SESSION['user_id'])) { // If this is the forum page, add a link for posting new threads: if (stripos($_SERVER['PHP_SELF'], 'forum.php')) { echo '<a href="post.php" class="navlink">' . $words['new_thread'] . '</a><br />'; } // Add the logout link: echo '<a href="logout.php" class="navlink">' . $words['logout'] . '</a><br />'; } else { // Register and login links: echo '<a href="register.php" class="navlink">' . $words['register'] . '</a><br /> <a href="login.php" class="navlink">' . $words['login'] . '</a><br />'; } // For choosing a forum/language:echo '</b><p><form action="forum.php" method="get"><select name="lid"><option value="0">' . $words['language'] . '</option>'; // Retrieve all the languages...$q = "SELECT lang_id, lang FROM languages ORDER BY lang_eng ASC";$r = mysqli_query($dbc, $q);if (mysqli_num_rows($r) > 0) { while ($menu_row = mysqli_fetch_array($r, MYSQLI_NUM)) { echo "<option value=\"$menu_row[0]\">$menu_row[1]</option>\n"; }}mysqli_free_result($r);unset($menu_row); echo '</select><br /><input name="submit" type="submit" value="' . $words['submit'] . '" /></form></p> </td> <td valign="top" class="content">';?> Link to comment Share on other sites More sharing options...
Antonio Conte Posted October 13, 2013 Share Posted October 13, 2013 Dude. I wrote you some steps to take in your first thread. Have you tried anything of that yet? Link to comment Share on other sites More sharing options...
aba Posted October 13, 2013 Author Share Posted October 13, 2013 sorry I don't seem to understand what u were taking about... Link to comment Share on other sites More sharing options...
Antonio Conte Posted October 13, 2013 Share Posted October 13, 2013 Huh? You have a total of four posts on this forum, in two threads. You don't really have to be a rocket scientist to figure it out. http://www.larryullman.com/forums/index.php?/topic/2717-help-on-ch-15/ Link to comment Share on other sites More sharing options...
aba Posted October 13, 2013 Author Share Posted October 13, 2013 Please Antonio send me ur email address so that I send the picture of the error for you to look at - I have tried sending it here but I can't upload pictures here... Thank you! Link to comment Share on other sites More sharing options...
Antonio Conte Posted October 15, 2013 Share Posted October 15, 2013 Try uploading the image to some image uploading site. I can't remember anyone now expect a Norwegian one called www.bildr.no, but you can at least use that. Something you can try is to place these on the top of your script. Some of the problem might be connected to your IF checks with $_SESSION. If those keys are not found, the code below might reveal some of the problem for you. init_set('display_errors', 1); init_set('error_reporting', -1); Get back to us. Link to comment Share on other sites More sharing options...
aba Posted October 15, 2013 Author Share Posted October 15, 2013 Link to comment Share on other sites More sharing options...
aba Posted October 15, 2013 Author Share Posted October 15, 2013 Link to comment Share on other sites More sharing options...
aba Posted October 15, 2013 Author Share Posted October 15, 2013 Link to comment Share on other sites More sharing options...
aba Posted October 15, 2013 Author Share Posted October 15, 2013 thank u Antonio, I've uploaded the image to www.bildr.no - the name of the image is php_erro... Link to comment Share on other sites More sharing options...
Recommended Posts