douza9835
douza9835
2016-12-30 11:09

我的搜索引擎项目结果页面上有些错误

  • mariadb
  • php
  • mysql
 <!DOCTYPE html>
 <html>
 <head>
 <meta charset="utf-8">
<title>Search Engine Project</title>
<link rel="stylesheet" type="text/css" href="css/styles.css">
<link rel="stylesheet" type="text/css" href="css/bootstrap.min.css">
</head>
<body>
<div class="container">
<form action="action.php" method="GET" class="search_form result-form"   autocomplete="off">
    <span class="result-header">Server Search</span>
    <input type="text" name="k" class="input result_input" value="<?php echo  $_GET['k'] ?>">
    <input type="submit" name="search" value="Search Web" class="search">
    </form>
    </div>


   <script src="js/bootstrap.min.js" ></script>
   <script src="js/jquery-3.1.1.min.js" ></script>
   <script src="js/javascript.js"></script>
   </body>
   </html>
   <?php 
   $q=$_GET['k'];
  if(isset($_GET['search'])){
  header("Location:https://www.google.co.in/?  gfe_rd=cr&ei=oyBmWN3FNvPx8Afe7a7IDA&gws_rd=ssl#q=$q");
  }
  if(isset($_GET['image'])){
  header("Location:https://www.google.co.in/search? site=&tbm=isch&source=hp&biw=1280&bih=670&q=$q");
  }
  if(isset($_GET['video'])){
   header("Location:https://www.google.com/search?  q=$q&biw=1280&bih=670&tbm=vid&source=lnms&sa=X&ved=0ahUKEwiJ_ruKxpvRAhVFgI8KHeVRBK4Q_AUICigD&dpr=1");
     }





  if(isset($_GET['local'])){
     mysql_connect("localhost", "root", "");
   mysql_select_db("search_query");
   $k = $_GET['k'];

if($k == "") {
echo "";
}
else {
$terms = explode(" ", $k);
$query= "SELECT * FROM search_table WHERE ";

foreach($terms as $each)
{
    $i=0;
    $i++;

    if($i==1)
    {
        $query .= "keywords LIKE '%$each%' ";
    }


    else
    {
        $query .= "OR keywords LIKE '%$each%' ";

    }

    }



  //query
   $query=mysql_query($query) or die(mysql_error());;
   $numrows= mysql_num_rows($query);
    if($numrows>0)
    {
        while($row = mysql_fetch_assoc($query))
        {
            $id= $row['id'];
            $title= $row['title'];
            $description= $row['description'];
            $keywords= $row['keywords'];
            $link= $row['link'];

            echo "<div style=''><h2><a href='$link'>$title</a></h2>
            $description</div> <hr><br/> <br/>";
        }

    }

    else
    {

        echo"No results found for \"<b>$k</b>\"";

    }


  //disconnect
   mysql_close();
   }
  }

  ?>

The above is the php code and the code searches the database in the mysql db and displays the approtiate result........

But when in the home page where i type the required keyword with lots of space before it and press search it gives a error type message :

You have an error in your SQL syntax; check the manual that corresponds to your MariaDB server version for the right syntax to use near 'keywords LIKE '%%' keywords LIKE '%%' keywords LIKE '%%' keywords LIKE '%%' keyw' at line 1 error"

I dont know what to do . I googled a lot in search for the fix.....

Images

PHP Error:

enter image description here

Blank Space input:

enter image description here

  • 点赞
  • 回答
  • 收藏
  • 复制链接分享

3条回答

为你推荐