我的SEARCH脚本出错

时间:2013-11-30 23:11:14

标签: php mysql search syntax

嘿伙计们我有错误  这是......

  

警告:mysql_query()[function.mysql-query]:无法通过/ home / content / 67/12055767中的套接字'/var/lib/mysql/mysql.sock'(2)连接到本地MySQL服务器第13行/html/Welcome.php

     

警告:mysql_query()[function.mysql-query]:无法在第13行的/home/content/67/12055767/html/Welcome.php中建立到服务器的链接   无法通过套接字'/var/lib/mysql/mysql.sock'连接到本地MySQL服务器(2)

我制作了一个搜索脚本。你能检查一下我的代码,看你是否能发现问题吗?

这是我的PHP

<?php

error_reporting(E_ALL);
ini_set('display_errors', '1');
$search_output = "";
if(isset($_POST['searchquery']) && $_POST['searchquery'] != ""){
    $searchquery = preg_replace('#[^a-z 0-9?!]#i', '', $_POST['searchquery']);
    if($_POST['filter1'] == "Companies"){
        $sqlCommand = "SELECT Company_ID, Company_Name AS company FROM Company WHERE Company_Name LIKE '%$searchquery%'";
    }
    include_once("database_connect.php");
        $query = mysql_query($sqlCommand) or die(mysql_error());
    $count = mysql_num_rows($query);
    if($count > 1){
        $search_output .= "<hr />$count results for <strong>$searchquery</strong><hr />$sqlCommand<hr />";
        while($row = mysql_fetch_array($query)){
                $id = $row->Company_ID;
            $Company_name = $row->Company_Name;
             $Image_path = $row->Image_path;
            $search_output .= "Item ID: $ $Image_path.$Company_name<br />";
                } // close while
    } else {
        $search_output = "<hr />0 results for <strong>$searchquery</strong><hr />$sqlCommand";
    }
}
?>

这是我的HTML表单(搜索框)

<form class="form-wrapper cf" action="<?php echo $_SERVER['PHP_SELF']; ?>" method="post">
        <input type="text" name="searchquery" maxlength="88" placeholder="Search for Company here..." required >
        <button type="submit" name="myBtn">Search</button>
        <select name="filter1" id="filterss">
<option value="Companies" selected="selected">Companies</option>
</select>

    </form>

ohhh和我的连接INCLUDE我有一个像这样的连接变量

$connection = mysqli_connect($dbhost, $dbuser, $dbpass, $dbname);

请帮帮我

1 个答案:

答案 0 :(得分:1)

您正在使用mysqli进行连接并使用mysql_*功能进行查询。这些是不同的库。

使用mysql_connect我不推荐使用{I},因为此库已被弃用或使用mysqli函数。请参阅此处以获取示例:Mysqli