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) {
 
    // 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 = "";
            }
 
    // 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 = "SELECT cards.card_id, series.series_name, cards.card_player,cards.card_condition
    FROM cards, series
    WHERE cards.cards_id = series.series_id";
 

    // Restrict the SQL query with an AND clause if a
    // series id has been supplied
    if ($form_series_id != 0)
     { $query .= "AND series.series_id = $form_series_id "; }
 
    // if player name  has been supplied
    if ($form_card_player != "")
    {
        $query .= " AND cards.card_player= '$form_card_player'";
    }
 
    // Restrict the SQL query with an AND clause if a contract  status has been supplied
    if ($form_card_condition != "")
    {
         $query .= "AND cards.card_condition = $form_card_condition ";
     }
 

 
    //this will check the value put by the user in the lowest price  box by the user
    //if ($form_lowest_price != "")
    //{
        //$query .= " AND card_price >= $form_lowest_price";
    //}

    //this will check the value put by the user in the highest price  box by the user
    //if ($form_highest_price != "")
    //{
        //$query .= " AND card_price <= $form_highest_price"; // 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 "No search results found...please search again";
    }
    else
    {
 
    // this contain the header information in the cell of the table
        echo <<<END
        <Table  width='60%' border="1">
         <TR>
            <TH>Card Id</TH>
            <TH>Series</TH>
            <TH>Player </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
        $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 "<TD>Mint</TD>";
        }
        elseif ($card_condition == 2)
        {
            Echo "<TD>Good</TD>";
        }
        elseif ($card_condition == 3)
        {
            Echo "<TD>Very Good</TD>";
        }
        //$card_price = $row['card_price'];

 
    // this will show  data from database in the table format what we require in assignment
        Echo "<TR >";
 
        Echo "<TD>$card_id_id</TD>";
        Echo "<TD>$series_name</TD>";
        Echo "<TD>$card_player</TD>";
        Echo "<TD>$card_condition</TD>";
 
         "</TR>";
 
    }
    Echo "</TABLE>";
}
 
// 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 400
1 Jochen Arndt 190
2 Richard MacCutchan 135
3 DamithSL 95
4 Garth J Lancaster 90
0 OriginalGriff 6,045
1 DamithSL 4,601
2 Maciej Los 4,032
3 Kornfeld Eliyahu Peter 3,480
4 Sergey Alexandrovich Kryukov 3,220


Advertise | Privacy | Mobile
Web03 | 2.8.141220.1 | Last Updated 5 Jun 2012
Copyright © CodeProject, 1999-2014
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