What is wrong? I have a script in which the first and last name is searched in the lines with activation = 1 it seems to me that the problem is in the $ getName line (line 9) here's the code: http://pastebin.com/hJK3sJWf

<table> <? include('bd.php'); $searchq = $_GET['name']; $myrow = mysql_query('SELECT * FROM users '); $nameArr = explode(" ", $searchq);//Разделяем входную строку на 2 по пробелу $getName = mysql_query(' SELECT * FROM users WHERE (firstname LIKE "%'.mysql_real_escape_string(addslashes($searchq)).'%" AND activation=1) OR ( lastname LIKE "%'.mysql_real_escape_string(addslashes($searchq)).'%" AND activation=1) OR ( firstname LIKE "%'.mysql_real_escape_string(addslashes($nameArr[0])).'%" AND lastname LIKE "%'.mysql_real_escape_string(addslashes($nameArr[1])).'%" AND activation=1) OR ( lastname LIKE "%'.mysql_real_escape_string(addslashes($nameArr[0])).'%" AND firstname LIKE "%'.mysql_real_escape_string(addslashes($nameArr[1])).'%" AND activation=1) '); while ($row = mysql_fetch_array($getName)){ echo " <tr align='left'> <div class='all_users'> <td> <a href='page.php?id=".$row['id']."'> <img src='".$row['avatar']."' title='".$row['lastname']." ".$row['firstname']."'> </a> </td> <td> ".$row['login']."<br> ".$row['lastname']." ".$row['firstname']."<br> ".$row['school'].", ".$row['school_form']."<br> ".$row['date_of_birth']."<br> </td> </div> </tr>"; } echo "</table><br><br><font size='5'><b>Інші користувачі</b></font><br><hr width='100%' color='blue'>"; ?> 

Closed due to the fact that off-topic participants Alexey Shimansky , cheops , user194374, aleksandr barakin , Mr. Black Aug 1 '16 at 17:29 .

It seems that this question does not correspond to the subject of the site. Those who voted to close it indicated the following reason:

  • “Questions asking for help with debugging (“ why does this code not work? ”) Should include the desired behavior, a specific problem or error, and a minimum code for playing it right in the question . Questions without an explicit description of the problem are useless for other visitors. See How to create minimal, self-sufficient and reproducible example . " - Alexey Shimansky, cheops, Community Spirit, aleksandr barakin, Mr. Black
If the question can be reformulated according to the rules set out in the certificate , edit it .

  • What is the "not work" script? Any wrong behavior, error messages? - cheops pm
  • @cheops changed - BedOmar pm
  • change the tutorial, the monstrous code, and the mysql_ * functions just do not work in php7 - strangeqargo
  • 1 - show the code from bd.php so that you can offer you a fixed version of your code. As already noted, it is extremely outdated and looks awful. It needs to be updated. 2 - by your mistake: the code is correct, at first glance. Not enough data. Show what input is in $ _GET ['name'] and what the query returns. 3 - query to the database looks ... "oversaturated". Why repeat the same thing so many times? write "activation = 1" once, and then specify the rest via OR. And why screen again and again the same thing ... - Ivan Pshenitsyn

1 answer 1

For starters, I would recommend that you simplify the code to that kind. I note that this does not make it any better, as already noted, mysql _ * - functions are extremely outdated and have not been recommended for a long time. Instead, they should use mysqli _ * functions or, better yet, the OOP version of MySQLi.

 <table> <? include('bd.php'); $searchq = mysql_real_escape_string(addslashes($_GET['name'])); $myrow = mysql_query('SELECT * FROM users '); $nameArr = explode(" ", $searchq);//Разделяем входную строку на 2 по пробелу $getName = mysql_query(' SELECT * FROM users WHERE activation=1 AND ( firstname LIKE "%'.$searchq.'%" OR lastname LIKE "%'.$searchq.'%" OR (firstname LIKE "%'.$nameArr[0].'%" AND lastname LIKE "%'.$nameArr[1].'%") OR (lastname LIKE "%'.$nameArr[0].'%" AND firstname LIKE "%'.$nameArr[1].'%") ) '); while ($row = mysql_fetch_array($getName)){ echo " <tr align='left'> <div class='all_users'> <td> <a href='page.php?id=".$row['id']."'> <img src='".$row['avatar']."' title='".$row['lastname']." ".$row['firstname']."'> </a> </td> <td> ".$row['login']."<br> ".$row['lastname']." ".$row['firstname']."<br> ".$row['school'].", ".$row['school_form']."<br> ".$row['date_of_birth']."<br> </td> </div> </tr>"; } echo "</table><br><br><font size='5'><b>Інші користувачі</b></font><br><hr width='100%' color='blue'>"; ?> 

For a specific solution to your problem, add data to the question.

 var_dump($_GET['name'], $getName, $row); 
  • var_dump ($ _ GET ['name'], $ getName, $ row); what is it? What is it for and where is it ?? You can detail - BedOmar
  • Google var_dump, well, what do you really ... var_dump displays information about the specified variables. Add this line to the code and we will see that in each of these variables. - Ivan Pshenitsyn