我的数据库搜索中的php错误&节目

时间:2013-11-17 19:59:33

标签: php mysql

所以我的数据库现在出现了各种各样的错误:

<?php
include("includes/db_conx.php");
?>


        <?php

    $query = $_POST['query'];

    $min_length = 1;
  if(strlen($query) >= $min_length)
  {
        $query = htmlspecialchars($query);
        $query = mysqli_real_escape_string($query);
        echo "";


      echo "Image results for <span style='color: #d34639;'>$query</span>" . "<br /><hr />";

        $result = mysqli_query($connection, "SELECT * FROM smd_members WHERE mem_username LIKE '$query' ");
        if(!$result){ die(mysqli_error($connection)); }
        if(mysqli_num_rows($result) > 0){
            while($row = mysqli_fetch_assoc($result)){
                echo "<a class='usersearch' href='#'><br />".$row['title']."<br /></a><span style='color: #000; font-size: 10pt;'>".$row['title']."<br /></span>";
                }
            }
        else{
            echo "Sorry..No results for $query";
            echo ""; 
        }  
    }
    else{
        echo "Your search keyword contains letters only ".$min_length;
    }
?>

以上是我的搜索文件,应显示结果,但我收到此错误:

警告:mysqli_real_escape_string()预计在第16行的/var/www/vhosts/jennys-cupcakes.co.uk/marble/search.php中给出了2个参数,1个图像结果 注意:未定义的变量:第22行/var/www/vhosts/jennys-cupcakes.co.uk/marble/search.php中的连接警告:mysqli_query()期望参数1为mysqli,在/ var / www /中给出null第22行的vhosts / jennys-cupcakes.co.uk / marble / search.php注意:未定义的变量:第23行的/var/www/vhosts/jennys-cupcakes.co.uk/marble/search.php中的连接警告: mysqli_error()期望参数1为mysqli,在第23行的/var/www/vhosts/jennys-cupcakes.co.uk/marble/search.php中给出为null

1 个答案:

答案 0 :(得分:0)

检查数据库连接

ad试试这个

$db = new mysqli(DB_HOST, DB_USER, DB_PASS, DB_NAME);