Results 1 to 6 of 6

Thread: Search Engine through PHP

  1. #1
    Join Date
    May 2008
    Posts
    2,680

    Search Engine through PHP

    Hi,

    This is my third script that I have a small problem:

    My search engine.

    Here's the script search form:
    Code:
    <code type="php"> 
    
    <form method="POST" action="recherche.php"> 
    
    Enter a keyword: <br> 
    
    <input type="text" name="Mot" size="15"> 
    
    <input type="submit" value="Rechercher" alt="Lancer the recherche!"> 
    
    </ form> 
    
    </ code> 
    
    Here's the script display search results: 
    
    <code type="php"> 
    
    <? php 
    $ host = localhost; 
    $ user = "root"; 
    $ password = ""; 
    $ db = "abcfibromyalgie"; 
    
    mysql_connect ($ host, $ user, $ password) or die ( "Connection to server"); 
    
    / / We choose the correct basis 
    mysql_select_db ($ db) or die ( "Connecting to db"); 
    
    echo " 
    <html> 
    
    <head> 
    
    <title> Search Results </ title> 
    
    </ head> 
    
    <body> "; 
    
    if (($ "")||($ Word word == == ("%")) 
    / / If a keyword has been seized, 
    / / Script asks the user 
    / / Kindly specify a keyword 
    
    echo " 
    Please enter a keyword please! 
    <p> "; 
    
    ) 
    
    else ( 
    / / On selected records containing the keyword 
    / / Or keywords in the title 
    $ query = "SELECT distinct count (link) FROM search 
    WHERE keyword LIKE \ "Mot% $% \" 
    OR LIKE title \ "% $% word \" 
    "; 
    
    $ result = mysql_query ($ query); 
    
    $ row = mysql_fetch_row ($ result); 
    
    $ Number = $ row [0]; 
    
    / / If no record is returned 
    / / Displays a message appropriate 
    if ($ Number == "0") ( 
    echo " 
    <h2> No results matched your search </ h2> 
    
    <p> 
    
    "; 
    
    ) 
    
    / / Otherwise, it displays the number of records corresponding 
    / / And the results themselves 
    else ( 
    $ query = "SELECT distinct link, keyword, title search FROM 
    WHERE keyword LIKE \ "Mot% $% \" 
    OR LIKE title \ "% $% word \" order by title ASC "; 
    
    $ result = mysql_query ($ query); 
    
    / / If only one record is found, it displays a message in the singular 
    if ($ Number == "1") ( 
    echo " 
    <a name=\"#resultat\"> <h2> Result: An article found </ h2> </ a> 
    
    <p> "; 
    
    ) 
    / / In case the message is plural ... 
    else ( 
    echo " 
    <a name=\"#resultat\"> <h2> Result: $ Number items found </ h2> </ a> 
    
    <p> "; 
    
    ) 
    while ($ row = mysql_fetch_row ($ result)) 
    ( 
    echo " 
    <p> \ n 
    <b> $ row [2] </ b> \ n 
    <br> <a href=\"../$row[0]\"> View article </ a> \ n 
    <p> \ n 
    "; 
    
    ) 
    ) 
    
    ) 
    
    / / On the firm basis 
    mysql_close (); 
    
    > 
    
    </ body> 
    
    </ html> 
    </ code> 
    
    Here is the first code of BDD: 
    
    <code type="sql"> -- 
    -- 
    - Structure of the table `search` 
    -- 
    
    CREATE TABLE `search` ( 
    `link` varchar (128) NOT NULL, 
    `` keyword text, 
    `title` varchar (128) default NULL, 
    `id` int (11) NOT NULL default'0 ', 
    PRIMARY KEY ( `id`) 
    ) ENGINE = InnoDB DEFAULT CHARSET = latin1; 
    
    </ code>
    Here the problem is that when I type a word into a search engine that I and my valid request, I see no results even if the word is that BDD is present

    So if some of you have a solution.

    Thank you in advance ...

  2. #2
    Join Date
    May 2008
    Posts
    2,012
    You will have to add $ word = $ _POST [ 'word']

  3. #3
    Join Date
    May 2008
    Posts
    2,680
    It's good it worked, for i was against putting $ word = $ _POST [ 'word'] with word and not capitalized word or it did not work.

    Thank you very much for the quick response.

  4. #4
    Join Date
    May 2008
    Posts
    2,297
    Well, finally instead:
    $ Word = mysql_real_escape_string ($ _POST [ 'word']);

    But it is just a recommendation, strongly advisable, but hey ... Everyone has the right to choose not to secure a request!

  5. #5
    Join Date
    May 2008
    Posts
    2,012
    You are right Zecho.

    I discovered this fact. I used one of my creation but a bit old.
    Thank you.

  6. #6
    Join Date
    May 2008
    Posts
    2,680
    I quite agree with you. I make the change, but if not the primary goal was to pass the request, after securing I'm not there yet.

    I'm only room for the moment.

    Thank you all.

Similar Threads

  1. Which is the best Web Search Engine?
    By Maq.H in forum Polls & Voting
    Replies: 7
    Last Post: 04-12-2013, 03:53 PM
  2. Which search engine do you use?
    By gangol in forum Polls & Voting
    Replies: 1
    Last Post: 10-08-2012, 06:47 PM
  3. in. search-results as search engine instead of Google
    By Eseld in forum Networking & Security
    Replies: 5
    Last Post: 15-07-2011, 07:23 PM
  4. Replies: 2
    Last Post: 27-06-2009, 01:15 PM
  5. Replies: 0
    Last Post: 07-11-2008, 02:15 PM

Tags for this Thread

Bookmarks

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •  
Page generated in 1,711,694,614.75388 seconds with 17 queries