新手求教!关于搜索的一个有关问题

WBOY
Release: 2016-06-13 12:33:38
Original
758 people have browsed it

新手求教!关于搜索的一个问题
自学php,做搜索框时遇到个问题,当我输入搜索的字符串只要是空格开头后面随便什么都可以,他都就会把表里全部数据都显示出来,弄了半天不明白是什么问题,额,代码是这样的
if(isset($_GET['sousuok'])){
    if(ctype_space($_GET['sousuok'])){
    echo "非法数据!";
    }else{
    $s=explode(" ",$_GET['sousuok']);
    require_once '../connvar.php';
    $dbc=mysqli_connect(DB_HOST,DB_USER,DB_PASSWORD,DB_NAME);
    mysql_query("SET NAMES 'UTF8'");
    $exec="select * from cangku where name like '%$s[0]%' or '%$s[1]%';";
$result=mysqli_query($dbc,$exec);
if(mysqli_num_rows($result)>0){
while($rs=mysqli_fetch_object($result)){
$name=$rs->name;
$tu=$rs->biaoqiantu;
echo "

".$name." 新手求教!关于搜索的一个有关问题 "."

";
};
echo mysqli_num_rows($result);
}else{
    echo mysqli_num_rows($result);
    echo "没有找到!";
    };
        mysqli_free_result();//释放内存
        mysqli_close();//断开数据库
    }
}

?>
Related labels:
source:php.cn
Statement of this Website
The content of this article is voluntarily contributed by netizens, and the copyright belongs to the original author. This site does not assume corresponding legal responsibility. If you find any content suspected of plagiarism or infringement, please contact admin@php.cn
Popular Tutorials
More>
Latest Downloads
More>
Web Effects
Website Source Code
Website Materials
Front End Template
About us Disclaimer Sitemap
php.cn:Public welfare online PHP training,Help PHP learners grow quickly!