PHP和Mysql创建一个简单的搜索栏

时间:2016-02-18 17:24:14

标签: php mysql

我正在尝试使用以下代码为我的网站创建一个简单的搜索栏,但是每当我运行该程序时,它一直说没有结果如果我在Navicat中查询它会显示结果。

<?php
include("config");
$query="select * from Books where Title like '%". $_POST['searchbar']."%' or Author like '%".$_POST['searchbar']."%'"; // create query using the $_GET 'id' sent
$result=mysql_query($query); //results from executing the mysql query
echo $query;
    if(!$result) // if not results
    {
    echo "No search results "; // print error
    }
    while($row=mysql_fetch_array($result)) // while there are results
    {
    echo 
    "<br>----------------------------------------------------------------------
    <br>Title:  ".$row['Title'].
    "<br>Author: ".$row['Author']. //print row price, name, author
    "<br>ISBN: ".$row['ISBN'].
    "<br>Condition: ".$row['BookCondition'].
    "<br>Price: ".$row['Price'].
    "<br>Sellers Username: ".$row['Uname'];
    echo"<br>";
    echo"----------------------------------------------------------------------";
    }
?>

如果您发现我的代码有任何问题,我们将不胜感激。

<?php
$host = '?'; //IP Address on domain name of the host for the database
$user ='?'; //the name of the user
$pass="?";//Our Password

//make the connection to the database
$con=mysql_connect($host,$user,$pass) or
die("Error connecting to Database");

$dbname = "?"; //we had a database name ?
mysql_select_db($dbname);
?>

0 个答案:

没有答案