lundi 21 mai 2018

The error says mysqli_num_rows() expects parameter 1 to be mysqli_result, boolean given in..., but parameter 1 do contain the result [duplicate]

I'm trying to create a simple search field. I've read the answers for questions that are very similar to mine, but I don't really see my mistake with this code. Whenever I hit the search button, it says "Warning: mysqli_num_rows() expects parameter 1 to be mysqli_result, boolean given in..." It says that there's something wrong with this line: $resultCheck = mysqli_num_rows($result);

    <?php
    if (isset($_POST['submitSearch'])) {
        $input = mysqli_real_escape_string($conn, $_POST['search']);
        $sql = "SELECT * FROM article WHERE a_title LIKE '%$input%' || a_text LIKE '%$input%' || a_author '%$input%' || a_date LIKE '%$input%'";
        $result = mysqli_query($conn, $sql);
        $resultCheck = mysqli_num_rows($result);
        if ($resultCheck > 0) {
            while ($row = msqli_fetch_assoc($resultCheck)) {
                echo "<div class='article-box'>
                    <h3> ".$row['a_title']." </h3>
                    <p> ".$row['a_text']." </p>
                    <p> ".$row['a_author']." </p>
                    <p> ".$row['a_date']." </p>
        </div>";
            }
        }
        else{
            echo "Your search did not match any document";
        }
    }

?>

I also made sure that I have the database connection at the top of my file. Please help me find where I went wrong.

Aucun commentaire:

Enregistrer un commentaire