I've been messing around with my search page. I added both mysqli_real_escape_string
and strip_tags
and as far as I can tell everything works fine and should be safe.
I was just trying to enter random symbols in the search form, to see whether all my database entries could still be found with these safety measures in place. All good, except when I search for a single quotation mark ('
).
This gives me the "mysqli_num_rows() expects parameter 1 to be mysqli_result, boolean given" error. There's a lot of information about that error and I know how to solve it (I thought so at least). However, in this particular case I have no clue :/
The code:
ini_set('display_errors', 1);
$search = $_GET ['q'];
$conn = mysqli_connect("localhost", "root", "","release");
$search = mysqli_real_escape_string($conn, "$search");
$search = stripslashes(strip_tags(trim("$search")));
$query = mysqli_query($conn,"SELECT * FROM game WHERE game_name LIKE '%". $search ."%' ORDER BY game_release");
$count = mysqli_num_rows($query);