使用php创建搜索框时出错

时间:2017-01-05 10:13:27

标签: php mysql

<?php
if(isset($_POST['query'])){
$query = $_POST['query'];
}

//create connection
$conn = mysql_connect("localhost", "root", "password");
mysql_select_db("bookclub", $conn);

?>
<html>

       <head>
          <meta charset="UTF-8">
          <link rel="stylesheet" type="text/css" href="style.css">
          <title> SearchBar </title>                      
        </head>            
              <body>
                 <header>


                    <form action="index.php" method="POST">

                    <input type="text"  name="query" placeholder="search...." maxlength="30" id="search">
                    <input type="submit"  name="submit" id="searchbtn" value="GO" />

                    </form>

<?php
$query = mysql_query("SELECT * FROM list WHERE BookName LIKE'%".$_POST['query'] ."%' OR Author LIKE '%".$_POST['query'] ."%' OR Price            LIKE'%".$_POST['query']."%'");  //line 53
$num_rows = mysql_num_rows($query);            
while($row = mysql_fetch_array($query)){

    $BookName = $row['BookName'];
    $Author = $row['Author'];
    $Price = $row['Price'];

    echo '<h3>'.$BookName.' By </h3> <p>' . $Author.'</p> Price: '  . $Price.'<br />'  ;
}
?>

                  </header>

              </body>            

  

注意:未定义的索引:第53行的C:\ xampp \ htdocs \ index.php中的查询

尝试了很多替代方案,但没有得到任何解决方案。即使有错误,我也可以搜索我的数据库表中的内容。我希望删除此错误。

0 个答案:

没有答案