0

This was working a second ago. I can't for the life of me figure out what went wrong.

Error: Warning: mysqli_fetch_array() expects parameter 1 to be mysqli_result, boolean given in C:\xampp\htdocs\PhpProject1\results.php on line 25

    <!DOCTYPE HTML>
    <html>
    <head>
        <link type="text/css" rel="stylesheet" href="Stylesheet.css"/>
        <title>Find Me the Goods</title>
    </head>

    <body>
        <a href="form.php" id="help">Help other people find the goods</a>
        <div class="container">

    <?php

   Error:Warning: mysqli_fetch_array() expects parameter 1 to be mysqli_result, boolean given in C:\xampp\htdocs\PhpProject1\results.php on line 25

 require("config.php");


    if(isset($_POST['submit'])){
    $searchTerm = $_POST['searchTerm'];
    }


    $result = mysqli_query($dbConn,"SELECT * FROM input WHERE country or region or townCity = '$searchTerm'");


    while($row = mysqli_fetch_array($result))
      {
    echo"<div id=resultsbox>";
    echo "<p id='date'>" . $row['theDate'] . "</p>";
     echo "<table border='0' id='resultsTable'>"; 
      echo "<tr><td><span>" . $row['townCity'] . "</span></td></tr>";
      echo "<tr><td>" . $row['region'] . "</td></tr>";
      echo "<tr><td>" . $row['country'] . "</td></tr>";
     echo "</table>";
      echo "<h1>Public smoking tolerance:" . " " . $row['tolerance'] . "/5</h1>";
      echo "<h1>Relevant Laws:</h1><p>" . $row['laws'] . "</p>";
      echo "<h1>Where to go to find it:</h1><p>" . $row['whereFind'] . "</p>";
      echo "<h1>What to expect to pay:</h1><p>" . $row['price'] . "</p>";
      echo "<h1>Addition information:</h1><p>" . $row['information'] . "</p>";
    echo"</div>";

      }
      ?>


    </div>


    </body>

    </html>
  • Can you `echo mysqli_error($dbConn);`? I'm thinking that the query failed. (Maybe the table doesn't exist, or $searchTerm has a single quote. (In that case, you should prepare the query instead) – Dave Chen Oct 07 '13 at 02:32
  • Welcome to Stack Overflow! Make sure you read the [about page](http://stackoverflow.com/about) for a quick run-through of this site's basic features. –  Oct 07 '13 at 02:38

1 Answers1

0

That error simply means that the MYSQLI returned an empty result set. Before your while loop, you should add:

if(empty($result)){
    echo "No results were found.";
}else{
    // while loop goes here
}

As far as making sure that your MYSQLI queries are secure goes, just do a bit of reading. Here are a few useful Stack Overflow sources:

Community
  • 1
  • 1