在未定义的变量中定义查询。

时间:2014-05-22 07:02:06

标签: php

我的搜索页面出错,服务器弹出消息:

  

注意:未定义的变量:查询输入   第64行/home/tz005/public_html/COMP1687/search.php最小长度   是3

我应该在哪里修改脚本以及如何定义查询?这是我的PHP脚本:

<?php

$min_length = 3; //min length of the search

if(strlen($query) >= $min_length){

        $query = htmlspecialchars($query); 

        $raw_results = mysqli_query($GLOBALS["___mysqli_ston"], "SELECT * FROM item_information
            WHERE (`itemtitle` LIKE '%".$query."%')") or die(((is_object($GLOBALS["___mysqli_ston"])) ? mysqli_error($GLOBALS["___mysqli_ston"]) : (($___mysqli_res = mysqli_connect_error()) ? $___mysqli_res : false)));


        if(mysqli_num_rows($raw_results) > 0){ // If it find's more than 0 results...

            while($results = mysqli_fetch_array($raw_results)){

echo "<p>".$results['itemtitle']."</p>"; // show's the results..


            }

        }
        else{ // If found nothing..
            echo "No results";
        }

    }
    else{ // if length of the search is less than defined on variable...
        echo "Minimum length is ".$min_length;
    }
?>

1 个答案:

答案 0 :(得分:1)

将行if(strlen($query) >= $min_length){更改为if(isset($query) && strlen($query) >= $min_length){