dongqun9403 2012-12-28 16:46
浏览 24

基本搜索引擎无法正常工作

Hello i managed to make a simple search engine its basic so i started working on that.. But i get Access Forbidden and dont know why can someone help me? with a form i give the $find the word i search and it should search for it.. thx for your time!`

    <?php

    if ($searching =="yes")  
    {   
    echo "Results";

    if ($find == "")   
    {   
    echo "You forgot to enter a search term";  
     exit;   
    }   
    mysql_connect("localhost","Anton","zouzou13") or die(mysql_error());  mysql_select_db("Ptyxiakh") or  die(mysql_error());
    $find = strtoupper($find);

    $find = strip_tags($find);

    $find = trim ($find);

    $data =mysql_query("SELECT * FROM documents WHERE keywords LIKE'%$find%'");  
     while($result = mysql_fetch_array( $data ))   
    {   
    echo $result['document_name'];   
    echo " ";
    echo $result['first_paragraph'];
    echo "<br>";     
    } 
     $anymatches=mysql_num_rows($data);
    if ($anymatches == 0)   
    {   
    echo "Sorry, but we can not find an entry to match your query<br><br>";   }
     echo "<b>Searched For:</b> " .$find;   }  ?>

ok i made it simpler to see if it works like this:

    <?php
    error_reporting(E_ALL);

    mysql_connect("localhost","Anton","zouzou13") or die(mysql_error()); 
    mysql_select_db("Ptyxiakh") or die(mysql_error()); 


     //Now we search for our search term, in the field the user specified 
     $data = mysql_query("SELECT * FROM documents WHERE keywords LIKE 'helmets'");

      while($result = mysql_fetch_array( $data ))   
    {   
    echo $result['document_name'];   
    echo " ";
    echo $result['first_paragraph'];
    echo "<br>";     
    }

     $anymatches=mysql_num_rows($data); 
     if ($anymatches == 0) 
     { 
     echo "Sorry, but we can not find an entry to match your query<br><br>"; 
     }
    ?> 
But i get the "Sorry, but we can not find an entry to match your query<br><br>"; so i cant connect to database?its just wont work :(



With PDO it should be like this??:

<?php
 //This is only displayed if they have submitted the form 
 if ($searching =="yes") 
 { 
 echo "<h2>Results</h2><p>"; 

 //If they did not enter a search term we give them an error 
 if ($find == "") 
 { 
 echo "<p>You forgot to enter a search term"; 
 exit; 
 } 
 $pdo = new PDO('mysql:host=localhost;dbname=ptyxiakh', 'Anton', 'zouzou13');
 // Otherwise we connect to our Database 
//mysql_connect("localhost","Anton","zouzou13") or die(mysql_error()); 
//mysql_select_db("Ptyxiakh") or die(mysql_error()); 

 // We preform a bit of filtering 
 $find = strtoupper($find); 
 $find = strip_tags($find); 
 $find = trim ($find); 

 //Now we search for our search term, in the field the user specified 
 //$data = mysql_query("SELECT * FROM documents WHERE keywords LIKE'%$find%'"); 
 $data= $pdo->query("SELECT * FROM documents WHERE keywords LIKE'%$find%'");

 //And we display the results 
 while($row = $statement->fetch(PDO::FETCH_ASSOC)) 
 { 
 echo htmlentities($row['document_name']); 
 echo " "; 
 echo htmlentities($row['first_paragraph']);
 echo "<br>";   
 } 

 //This counts the number or results - and if there wasn't any it gives them a little message explaining that 
 $anymatches=mysql_num_rows($data); 
 if ($anymatches == 0) 
 { 
 echo "Sorry, but we can not find an entry to match your query<br><br>"; 
 } 

 //And we remind them what they searched for 
 echo "<b>Searched For:</b> " .$find; 
 } 
?> 
  • 写回答

1条回答 默认 最新

  • douguomou5094 2012-12-28 22:39
    关注

    i made it work its pretty basic and i guess it has deprecated thingys but il upload for ppl that search for things... just make a simple form and then make a php file

        <?php
     error_reporting(E_ALL);
     //This is only displayed if they have submitted the form 
     echo "<h2>Results</h2><p>"; 
     $find =$_POST["find"];
     //If they did not enter a search term we give them an error 
     if ($find == "") 
     { 
     echo "<p>You forgot to enter a search term"; 
     exit; 
     } 
     // Otherwise we connect to our Database 
     mysql_connect("localhost","Anton","zouzou13") or die(mysql_error()); 
     mysql_select_db("Ptyxiakh") or die(mysql_error()); 
    
     // We preform a bit of filtering 
     $find = strtoupper($find); 
     $find = strip_tags($find); 
     $find = trim ($find); 
    
     //Now we search for our search term, in the field the user specified 
     $data = mysql_query("SELECT * FROM documents WHERE keywords LIKE'%$find%'"); 
    
     //And we display the results 
      while($result = mysql_fetch_array( $data ))   
        {
        echo '<p> <strong>',$result['document_name'], '</strong> <br> ', $result['first_paragraph'],'... <br> </p>';
        }
    
     //This counts the number or results - and if there wasn't any it gives them a little message explaining that 
     $anymatches=mysql_num_rows($data); 
     if ($anymatches == 0) 
     { 
     echo "Sorry, but we can not find an entry to match your query<br><br>"; 
     } 
    
     //And we remind them what they searched for 
     echo "<b>Searched For:</b> " .$find; 
    
    ?> 
    

    This worked for me :) thx!

    评论

报告相同问题?

悬赏问题

  • ¥15 关于无人驾驶的航向角
  • ¥15 keil的map文件中Image component sizes各项意思
  • ¥30 BC260Y用MQTT向阿里云发布主题消息一直错误
  • ¥20 求个正点原子stm32f407开发版的贪吃蛇游戏
  • ¥15 划分vlan后,链路不通了?
  • ¥20 求各位懂行的人,注册表能不能看到usb使用得具体信息,干了什么,传输了什么数据
  • ¥15 Vue3 大型图片数据拖动排序
  • ¥15 Centos / PETGEM
  • ¥15 划分vlan后不通了
  • ¥20 用雷电模拟器安装百达屋apk一直闪退