0

I'm new to php coding I reviewed all the questions I could find about this, but it doesn't seam to be the be the same question.

I think it's a problem with my $query but I can't find it or am just not experienced enough. My $query is running not like in other questions, this is the error:

"Warning: mysqli_num_rows() expects parameter 1 to be mysqli_result, boolean given in bla/bla/bla/index.php on line 10"

here's my code:

    <?php
    $con = mysqli_connect('localhost','root','','littlehelper');
        if (isset($_POST['keywords'])) {
            $k = $_POST['keywords'] ;
            if(!empty($k)) {
                $query = "SELECT * FROM 'search' WHERE * LIKE '%".mysqli_real_escape_string($con, $k)."%'" ;
                $query_run = mysqli_query($con, $query);

        // Check if it is a boolean, then check if we have rows (not nice, but workable)
        if($query_run !== false && mysqli_num_rows($query_run)>=1) {
            echo 'found' ;
        } else {
            echo 'not found';
        }
    }
}
    ?>

thanks for every help i can get

Raphioly-San
  • 405
  • 3
  • 10
Djail
  • 1
  • 1
  • Have you tried running the query directly in SQL? (perhaps using phpMyAdmin) Like the answer below, it probably returning a `FALSE` and not a result object... – Raphioly-San May 31 '16 at 08:33
  • Boolean given means that `mysqli_query` has returned `false`, because your query failed. You should get in the habit of checking the result of your queries to avoid such warnings. The error is likely due to be because you used normal quotes (') instead of backticks (\`) in your query on the table name. As @nospor mentioned below `* LIKE` makes no sense either. You need to specify a column name instead of `*` – Jonathon May 31 '16 at 08:34
  • is there a possibility to not check for a specific column? Thanks a lot for the feedback!! it all makes sense now =) – Djail May 31 '16 at 08:40
  • why need you * there ? – JYoThI May 31 '16 at 08:43

1 Answers1

1

'search' - this means this is text. THis is table name not text so it should be like this:

SELECT * FROM `search` WHERE .....

And what is it * LIKE ? There must be column name not *

nospor
  • 4,150
  • 1
  • 14
  • 25