K
K
kiril90112018-05-13 16:47:36
PHP
kiril9011, 2018-05-13 16:47:36

How to do a search?

there is a code:

<?php

$search_q=$_POST['search_q'];

$l= mysqli_connect('localhost', 'Логин', 'пароль', 'БД');
$search_q = trim($search_q);

$search_q = strip_tags($search_q);

$q= mysqli_query($l, "SELECT name,author FROM `book` WHERE name LIKE '%$search_q%'");

$itog=mysqli_fetch_assoc($q);

while ($itog = mysqli_fetch_assoc($q)) {

printf("%s (%s)\n",$r["name"],$r["author"]);

}

mysqli_free_result($q);

mysqli_close($l);

?>

I need to search by name and author, but a white screen, what's wrong?

Answer the question

In order to leave comments, you need to log in

2 answer(s)
S
Sergey, 2018-05-13
@kiril9011

WHERE name LIKE '%$search_q%' OR author LIKE '%$search_q%'

A
Alexey Ukolov, 2018-05-13
@alexey-m-ukolov

printf("%s (%s)\n",$r["name"],$r["author"]);
Where is your variable defined with the name $r? That's right - nowhere, that's why everything falls. $itog['name']should be.
Developing with errors turned off is a dubious pleasure.

Didn't find what you were looking for?

Ask your question

Ask a Question

731 491 924 answers to any question