greeny_big Posted June 1, 2007 Share Posted June 1, 2007 "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 Quote Link to comment https://forums.phpfreaks.com/topic/53835-mysqli_num_rows-expects-parameter-1-to-be-mysqli_result-boolean/ Share on other sites More sharing options...
chigley Posted June 1, 2007 Share Posted June 1, 2007 On line 72, use: $result = mysqli_query($link, $query) or die(mysqli_error($link)); I'd say your query must be failing. Probably because you haven't selected a database! Quote Link to comment https://forums.phpfreaks.com/topic/53835-mysqli_num_rows-expects-parameter-1-to-be-mysqli_result-boolean/#findComment-266139 Share on other sites More sharing options...
greeny_big Posted June 1, 2007 Author Share Posted June 1, 2007 wats the correct way of putting, ORDER BY comics.comic_id ASC Quote Link to comment https://forums.phpfreaks.com/topic/53835-mysqli_num_rows-expects-parameter-1-to-be-mysqli_result-boolean/#findComment-266142 Share on other sites More sharing options...
greeny_big Posted June 1, 2007 Author Share Posted June 1, 2007 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 Quote Link to comment https://forums.phpfreaks.com/topic/53835-mysqli_num_rows-expects-parameter-1-to-be-mysqli_result-boolean/#findComment-266145 Share on other sites More sharing options...
greeny_big Posted June 1, 2007 Author Share Posted June 1, 2007 Scrap that, problem solved Just need to do error checking now Quote Link to comment https://forums.phpfreaks.com/topic/53835-mysqli_num_rows-expects-parameter-1-to-be-mysqli_result-boolean/#findComment-266147 Share on other sites More sharing options...
chigley Posted June 1, 2007 Share Posted June 1, 2007 You need quotes around the value: [pre]AND comics.comic_issue = '$form_comic_issue'[/pre] Quote Link to comment https://forums.phpfreaks.com/topic/53835-mysqli_num_rows-expects-parameter-1-to-be-mysqli_result-boolean/#findComment-266148 Share on other sites More sharing options...
Recommended Posts
Join the conversation
You can post now and register later. If you have an account, sign in now to post with your account.