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>
4

1 回答 1

0

该错误仅意味着 MYSQLI 返回了一个空结果集。在您的 while 循环之前,您应该添加:

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

至于确保您的 MYSQLI 查询是安全的,只需阅读一下。以下是一些有用的 Stack Overflow 资源:

于 2013-10-07T02:36:31.333 回答