Warning: file_get_contents(/data/phpspider/zhask/data//catemap/1/php/245.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
Php 站点搜索是否显示整个表而不是搜索结果?_Php_Sql_Database_Mysqli - Fatal编程技术网

Php 站点搜索是否显示整个表而不是搜索结果?

Php 站点搜索是否显示整个表而不是搜索结果?,php,sql,database,mysqli,Php,Sql,Database,Mysqli,我有一个数据库,员工信息显示在一个表中,我已经成功地创建了搜索框,我已经连接到我的数据库,现在的问题是,当我搜索名称,即“Daniel”时,它只会返回我已经拥有的表,因此有两个表而不是“Daniels”信息 这是我的密码- <!doctype html> <html> <head> <title></title> <link rel="stylesheet" href=".

我有一个数据库,员工信息显示在一个表中,我已经成功地创建了搜索框,我已经连接到我的数据库,现在的问题是,当我搜索名称,即“Daniel”时,它只会返回我已经拥有的表,因此有两个表而不是“Daniels”信息

这是我的密码-

<!doctype html>
  <html>
       <head>
          <title></title>
          <link rel="stylesheet" href="../Css/index_stylesheet.css">
       </head>
  <body>
    <p>

    <?php
        $form = "<html>
        <h1>Search!</h1>
        <form method=\"get\">
          <label>Name:
          <input type=\"text\" name=\"keyname\" />
          </label>
          <input type=\"submit\" value=\"Search\" />
        </form>
        </body>
        </html>";
            //capture search term and remove spaces at its both ends if there is any

            if(!empty($_GET['keyname'])){
            $keyname = $_GET['keyname'];

            $searchTerm = trim($keyname);

            //database connection info
            $host = "localhost"; //server
            $db = "development_suite"; //database name
            $user = "root"; //dabases user name
            $pwd = ""; //password

            //connecting to server and creating link to database
            $link = mysqli_connect($host, $user, $pwd, $db);

            //MYSQL search statement
            $query = "SELECT  firstname ,surname,address,mobile,email
                        FROM development_suite.eeg_staff;";

            $results = mysqli_query($link,$query);

            /* check whethere there were matching records in the table
            by counting the number of results returned */
            if(mysqli_num_rows($results) >= 1){
                $output = "$row_1";
                while($row = mysqli_fetch_array($results))
                {
                    $output .= "First Name: " . $row['firstname'] . "<br />";
                    $output .= "Surname: " . $row['surname'] . "<br />";
                    $output .= "Address: " . $row['address'] . "<br />";
                    $output .= "Mobile: " . $row['mobile'] . "<br />";
                    $output .= "Email: " . $row['email'] . "<br /><br />";



                }
            }else{
                $output = "There was no matching record for the name " .
                strip_tags($searchTerm);             
            }

        } else {
            $output = "Enter name you are searching for.";
        }


            echo "$form\n$output";
        ?>
     </body>
 </html>



您必须在查询中添加where子句。类似于

$query = "SELECT  firstname ,surname,address,mobile,email
                    FROM development_suite.eeg_staff 
                    WHERE firstname LIKE '" . $_REQUEST['keyname'] . "';";
致以最良好的祝愿,
内博伊萨(Nebojsa)

不过,我应该在这条线上写些什么?出现错误,“警告:mysqli_num_rows()期望参数1是mysqli_result,在第49行的C:\wamp\www\manholeform\Application\includes\search_function.php中给出的布尔值”第49行是以if(mysqli_num_rows($results)try echo$query开头的if语句,用于输出查询并尝试直接在数据库上执行该查询。