Click here to Skip to main content
Rate this: bad
good
Please Sign up or sign in to vote.
Hi

I am trying to run my search form and getting this error on result page

Warning: mysqli_num_rows() expects parameter 1 to be mysqli_result, boolean given in /Applications/XAMPP/xamppfiles/htdocs/m/results.php on line 84
No search results found...please search again

My code for result page :

<?php
// Check that the form has been submitted
if ($_POST) {
 
<pre>
// Store the form data in variables

$form_series_name = $_POST['series_name'];
$form_card_player = $_POST['card_player'];
$form_card_condition = $_POST['card_condition'];
//$form_card_price = $_POST['card_price'];

// Check if the radio button data exists
 if (array_key_exists('card_condition', $_POST))
 {
 $form_card_condition = $_POST['card_condition'];
  }
  else
  {
    $form_card_condition = &quot;&quot;;
        }
 
// Trim any trailing and leading spaces from the form data
$form_series_name = trim($form_series_name);
$form_card_player = trim($form_card_player);
$form_card_condition = trim($form_card_condition);
 
// Open a connection to the database
$link = mysqli_connect(----------my values-------);
 
// Define a query that retrieves all fields names and id
$query = &quot;SELECT cards.card_id, series.series_name, cards.card_player,cards.card_condition
FROM cards, series
WHERE cards.cards_id = series.series_id&quot;;
 
// Restrict the SQL query with an AND clause if a
// series id has been supplied
if ($form_series_id != 0)
 { $query .= &quot;AND series.series_id = $form_series_id &quot;; }
 
// if player name  has been supplied
if ($form_card_player != &quot;&quot;)
{
    $query .= &quot; AND cards.card_player= '$form_card_player'&quot;;
}
 
// Restrict the SQL query with an AND clause if a contract  status has been supplied
if ($form_card_condition != &quot;&quot;)
{
     $query .= &quot;AND cards.card_condition = $form_card_condition &quot;;
 }
 
//this will check the value put by the user in the lowest price  box by the user
//if ($form_lowest_price != &quot;&quot;)
//{
    //$query .= &quot; AND card_price &gt;= $form_lowest_price&quot;;
//}

//this will check the value put by the user in the highest price  box by the user
//if ($form_highest_price != &quot;&quot;)
//{
    //$query .= &quot; AND card_price &lt;= $form_highest_price&quot;; // this will show the query
//}

// Run the query and store the result
$result = mysqli_query($link, $query);
 
$number = mysqli_num_rows($result);
 
//echo $query;

// this will show the whole tablle record from database if the user not select and type anything on query page
if ($number == 0)
{
    echo &quot;No search results found...please search again&quot;;
}
else
{
 
// this contain the header information in the cell of the table
    echo &lt;&lt;&lt;END
    &lt;Table  width='60%' border=&quot;1&quot;&gt;
     &lt;TR&gt;
        &lt;TH&gt;Card Id&lt;/TH&gt;
        &lt;TH&gt;Series&lt;/TH&gt;
        &lt;TH&gt;Player &lt;/TH&gt;
        &lt;TH&gt;Condition&lt;/TH&gt;
        //&lt;TH&gt;Price&lt;/TH&gt;

     &lt;/TR&gt;

END;
// Assign each record in the result to an array
while ($row = mysqli_fetch_array($result))
{
// Assign each array element to a variable
$card_id = $row['card_id'];
$series_name = $row['series_name'];
$card_player = $row['card_player'];
$card_condition = $row['card_condition'];
 
   if ($card_condition == 1)
    {
        Echo &quot;&lt;TD&gt;Mint&lt;/TD&gt;&quot;;
    }
    elseif ($card_condition == 2)
    {
        Echo &quot;&lt;TD&gt;Good&lt;/TD&gt;&quot;;
    }
    elseif ($card_condition == 3)
    {
        Echo &quot;&lt;TD&gt;Very Good&lt;/TD&gt;&quot;;
    }
    //$card_price = $row['card_price'];

// this will show  data from database in the table format what we require in assignment
    Echo &quot;&lt;TR &gt;&quot;;
 
    Echo &quot;&lt;TD&gt;$card_id_id&lt;/TD&gt;&quot;;
    Echo &quot;&lt;TD&gt;$series_name&lt;/TD&gt;&quot;;
    Echo &quot;&lt;TD&gt;$card_player&lt;/TD&gt;&quot;;
    Echo &quot;&lt;TD&gt;$card_condition&lt;/TD&gt;&quot;;
 
     &quot;&lt;/TR&gt;&quot;;
 
}
Echo &quot;&lt;/TABLE&gt;&quot;;

}

// Close the connection to the database
mysqli_close($link);

}

?>

[edit]add proper tag-johny[/edit]
Posted 25-May-12 3:16am
Edited 25-May-12 4:50am
v4
Rate this: bad
good
Please Sign up or sign in to vote.

Solution 1

You should check the result (that is $result) of mysqli_query before passing it to mysqli_num_rows, see the documentation [^].
  Permalink  
Rate this: bad
good
Please Sign up or sign in to vote.

Solution 2

you didnt select database. besides check res to ensure its working properly, if not then use mysql_error function to get the error message
  Permalink  
Rate this: bad
good
Please Sign up or sign in to vote.

Solution 3

I was using wrong SQL query.
 
// Define a query that retrieves all fields names and id
    $query = "SELECT cards.card_id, series.series_name, cards.card_player,cards.card_condition
    FROM cards, series
    WHERE cards.cards_id = series.cards_id ";

Thanks for your help guys.
  Permalink  

This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)

  Print Answers RSS
0 OriginalGriff 490
1 Sergey Alexandrovich Kryukov 405
2 Maciej Los 310
3 ProgramFOX 265
4 CHill60 200
0 OriginalGriff 490
1 Sergey Alexandrovich Kryukov 405
2 Maciej Los 285
3 ProgramFOX 265
4 Peter Leow 210


Advertise | Privacy | Mobile
Web03 | 2.8.150331.1 | Last Updated 5 Jun 2012
Copyright © CodeProject, 1999-2015
All Rights Reserved. Terms of Service
Layout: fixed | fluid

CodeProject, 503-250 Ferrand Drive Toronto Ontario, M3C 3G8 Canada +1 416-849-8900 x 100