-1

I am trying to make a search form on my site which prints all possible things that have come out of the database. However, when I search for something, it always gives me back that it can't find anything. How do I fix this?

PHP code:

$host = 'localhost';
$user = '111042';
$password = 'jcbvrjd8';
$db_name = '111042';
$search = $_POST["search"];
if(isset($search)) {
    $db = mysqli_connect($host, $user, $password, $db_name);
    $wild_search = "%".$search."%";
    $findname = "SELECT `name`,`surname`
                FROM `Account` 
                WHERE `name` LIKE '".$wild_search."'
                    OR `surname` LIKE '".$wild_search."'
                    OR CONCAT(`name`, `surname`) LIKE '".$wild_search."'
                    OR CONCAT(`name`, `surnameprefix`, `surname`) LIKE '".$wild_search."';";
    $query = mysqli_query($db,$findname);
    $results = mysqli_fetch_all($query);

    if($result) {
        echo "<div id='searchresult'>\n";
        echo "<h1>People Found:</h1>\n";
        echo "<table id='searchresult'>\n";
        foreach($result as $rowno => $row) {
            echo "<tr class='searchtablerow'>\n";
            echo "<td>".$row['name'].", ".$row['surname']."</td>\n";
            echo "</tr>\n";
        }
        echo "</table>\n";
    } else {
        echo "<div id='searchresult'><h1>People Found:</h1>\n";
        echo "<p>No one was found...</p>\n";
        echo "</div>\n";
    }
} else {
}

HTML form:

<div id="searchform">
    <h1>Search friends:</h1>
    <form name="searchform" method="post" action ="searchlink.php">
        <input type="text" name="search" id="search" autofocus placeholder="e.g. John Smith..."></input> <br>
        <input type="submit" name="submitsearch" value="Search" id="searchbutton"></input>
    </form>
</div>

Thank you guys for helping me.

PS. Please do not roast me, I'm just not as advanced as you are.

Qirel
  • 25,449
  • 7
  • 45
  • 62

1 Answers1

0
$query = mysqli_query($db,$findname);
$results = mysqli_fetch_all($query);

if ($results) {
...

"s" missing at end of result. (or delete the s in $results = mysqli_fetch_all($query);)

Niraj Shah
  • 15,087
  • 3
  • 41
  • 60
Peter
  • 1,247
  • 19
  • 33