Jump to content
Larry Ullman's Book Forums

Recommended Posts

Hi all,

 

Thanks for your help. I just tested the message board webpage after all of pages were built up. There are some warnings I got from header.html page. The warnings are below:

 

Warning: mysqli_num_rows() expects parameter 1 to be mysqli_result, boolean given in C:\xampp\htdocs\template-forums\includes\header.html on line 37

 

Warning: mysqli_fetch_array() expects parameter 1 to be mysqli_result, boolean given in C:\xampp\htdocs\template-forums\includes\header.html on line 47

 

Warning: mysqli_free_result() expects parameter 1 to be mysqli_result, boolean given in C:\xampp\htdocs\template-forums\includes\header.html on line 50

 

I don't know why I am having these.

I am attaching 'header.html' page below.

 

 

--------------------------------------------------------------------------------------------------------------------------------------------------------

<?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_fetch_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">';

?>

 

---------------------------------------------------------------------------------------------------------------------------------------------

 

Thanks for your help in advance and look forward to hearing from you soon.

Link to comment
Share on other sites

It is odd. I would guess that a DB connection is not properly being established, since all the errors are related to the $r variable, which is based off the DB connection and the query. Really not sure, but the issue might be in your included DB connection script.

  • Upvote 1
Link to comment
Share on other sites

 Share

×
×
  • Create New...