Php 在搜索框中获取结果

Php 在搜索框中获取结果,php,Php,我在我正在工作的系统上创建了一个搜索工具栏,但它不执行我正在搜索的内容,它总是不返回任何结果,即使在数据库的表中找到了我搜索的关键字。请帮助我分析我的代码,在我错过或错误的thnks提前。 这是我的密码。search.php <form method="post" action="search.php"> <p><input type="text" name="keywords"><input type="submit" value="

我在我正在工作的系统上创建了一个搜索工具栏,但它不执行我正在搜索的内容,它总是不返回任何结果,即使在数据库的表中找到了我搜索的关键字。请帮助我分析我的代码,在我错过或错误的thnks提前。 这是我的密码。search.php

    <form method="post" action="search.php">
     <p><input type="text" name="keywords"><input type="submit" value="Search"></p>
       </form>
       <?php
       include 'connect/func.inc.php';
       if(isset($_POST['keywords'])){
       $suffix = '';
    //trim is for ignoring spaces on the input type text
    $keywords = mysql_real_escape_string(htmlentities(trim($_POST['keywords'])));

    $errors = array();
    if(empty($keywords)){
        $errors[]='Please enter a search keyword';
        }
        else if (strlen($keywords)<0) { 
        //strlen is for the no. of char
        $errors[]='Please three or more characters';
        }else if (search_results($keywords) === false){
        $errors[]='Your search for '.$keywords.' returned no results';
        } 

        if (empty($errors)) {
        //search
        $results = search_results($keywords);
        $results_num = count($results);
        $suffix = ($results_num !=1) ? 's': '';
        echo '<p>Your search for<strong>'. $keywords.'</strong> returned <strong>'. $results_num .'</strong>result',$suffix, '</p>';
        foreach($results as $result) {
        echo '<p><strong>', $result['studId'], '</strong><br>', $result['fname'],  $result['mname'], $result['lname'],'</p>';

        }
            //print_r(search_results($keywords));
        } else {
            foreach($errors as $error) {
            echo $error, '</br>';
                                        }
        }
    }

   ?>

从外观上看,您引用的是一个不存在的列。在您的数据库结构中,哪里有一个名为“关键字”的列?我看不出来

从你在原始问题下的评论来看,你似乎应该改变

$where .= "`keywords` LIKE '%$keyword%'";


. 它们不再得到维护。看到了吗?相反,学习,并使用or-将帮助您决定哪一个。如果你选择PDO,当它说没有结果时,你在输入什么?@EM creates。。我键入“c-1111”,但它仍然返回否results@EM-创作。我想我知道我错在哪里了。。。。它在我的$where上。=“
关键字”
类似“%$keyword%”;我想更改一下,我想问一下是否可以添加更多的列名?怎么做?@EM。我是对的,现在我可以得到我的结果了…@EM Creations。。。是的,我实际上解决了我自己的问题,但有一件事我想问,我的$where变量中有可能有更多的列吗?@PotPot嗯,你可以通过添加OR来实现这一点,所以<代码>$where.=“(类似studId的“%$keyword%”或类似fname的“%$keyword%”)$EM创建。。。啊,好吧,现在我可以让我的搜索框更可靠。。。太多了
  studId    fname   mname   lname
  c-1111    peter   jan      yu
  c-1112    jane    trish    li
$where .= "`keywords` LIKE '%$keyword%'";
$where .= "`studId` LIKE '%$keyword%'";