Jump to content

mysqli_num_rows() expects parameter 1 to be mysqli_result, boolean


greeny_big

Recommended Posts

"mysqli_num_rows() expects parameter 1 to be mysqli_result, boolean given in C:\Program Files\xampp\htdocs\results1.php on line 75"

is the error message that appears.

 

Here is the code for the results page:

<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Strict//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-strict.dtd">

<html xmlns="http://www.w3.org/1999/xhtml" lang="en" xml:lang="en">

<head>

<meta http-equiv="Content-Type" content="text/html; charset=iso-8859-1"/>

<title>Comic Collectables - Search Results</title>

</head>

<body>

<h1>Comic Collectables - Search Results</h1>

<?

// Check that the form has been submitted

if ($_POST) {

 

// Store the form data in variables

  $form_series_name =    $_POST['series_name'];

  $form_comic_issue =    $_POST['comic_issue'];

  $form_comic_condition = $_POST['comic_condition'];

 

// Trim any trailing and leading spaces from the form data

  $comic_issue =    trim('$form_comic_issue');

 

// Open a connection to the database

$link = mysqli_connect('localhost', 'student', 'mmst12009', 'assignment3');

 

// Define an SQL query to retrieve the comic records

$query = "

  SELECT

 

    comics.comic_id,

series.series_name,

    comics.comic_issue,

    comics.comic_condition,

    comics.comic_price

 

  FROM

 

    comics,

    series

 

  WHERE

 

    (comics.series_id = series.series_id)

 

  ORDER BY

 

    comics.comic_id ASC";

 

// Restrict the SQL query with an AND clause if a

// comic issue has been supplied

if ($form_series_name != "")

 

{

$query .= "AND comics.comic_issue = $form_comic_issue ";

}

 

// Restrict the SQL query with an AND clause if a

// comic issue has been supplied

if ($form_comic_issue != "")

 

{

$query .= "AND comics.comic_issue = $form_comic_issue ";

}

 

// Restrict the SQL query with an AND clause if a

// comic condition has been supplied

if ($form_comic_condition != "")

 

{

$query .= "AND comics.comic_condition = '$form_comic_condition' ";

}

 

// Run the query and store the result

$result = mysqli_query($link, $query);

 

// Get the number of rows in the result set

$number_of_rows = mysqli_num_rows($result);Line 75.

 

// Close the connection to the database

mysqli_close($link);

 

// Display a message if no records have been retrieved

if ($number_of_rows == 0) {

  echo <<<END

<p>There are no records in the database.</p>

END;

}

else {

 

  // Display the head of the table

  echo <<<END

  <p>Search results are presented below.</p>

  <table border="0">

    <tr>

      <th>ID Number</th>

      <th>Series</th>

      <th>Issue</th>

      <th>Condition</th>

      <th>Price</th>

    </tr>

END;

 

  // Assign each record in the result to an array

  while ($row = mysqli_fetch_array($result))

  {

 

    // Assign each array element to a variable

    $comic_id =        $row['comic_id'];

    $series_name =    $row['series_name'];

    $comic_issue =    $row['comic_issue'];

    $comic_condition = $row['comic_condition'];

    $comic_price =    $row['comic_price'];

 

 

    // Display each record in a separate row of the table

    echo <<<END

    <tr>

      <td>$comic_id</td>

      <td>$series_name</td>

      <td>$comic_issue</td>

      <td>$comic_condition</td>

      <td>$$comic_price</td>

    </tr>

END;

    }

  echo "</table>";

  }

}

?>

</body>

</html>

 

Cheers,

Greeny

I'm now getting this error after I fixed something

 

You have an error in your SQL syntax; check the manual that corresponds to your MySQL server version for the right syntax to use near 'AND comics.comic_issue =' at line 20

Archived

This topic is now archived and is closed to further replies.

×
×
  • Create New...

Important Information

We have placed cookies on your device to help make this website better. You can adjust your cookie settings, otherwise we'll assume you're okay to continue.