mysql_fetch_array()期望参数1是资源,给定布尔值

时间:2017-05-22 08:20:09

标签: mysql field multiple-columns

我试图用多个输入字段搜索我的数据库。并非所有领域都是必要的。当我搜索并填满所有字段时,它会给出结果。当我只使用第一个字段进行搜索时,它会给出结果。但是当第一个字段为空而其他字段有值时,它会给我这个错误:

MySQL_fetch_array()期望参数1为资源,布尔给定

这是我的代码:

<?php
mysql_connect("localhost","root",""); 
mysql_select_db("autocomplete") or die("Unable to select database"); 

if(isset($_GET['Submit']))
{

    $usearchprofile = @$_GET['profile_number'];
    $usearchnicename = @$_GET['nice_name'];
    $usearchiso3 = @$_GET['iso_3'];

    $qrystring = "SELECT * FROM country where ";  

    if($usearchprofile)
        $qrystring .= " name like '%".$usearchprofile."%'  ";    

    if($usearchnicename)
        $qrystring .= " OR nicename like '%".$usearchnicename."%'  ";

    if($usearchiso3)
        $qrystring .= " OR iso3 like '%".$usearchiso3."%'  ";


    $userarray = mysql_query($qrystring);

    while ($usrow = mysql_fetch_array($userarray))
    {
        echo $usrow['name'];
        echo $usrow['nicename'];
        echo $usrow['iso3'];
    }
}
?>

0 个答案:

没有答案