Go Back   TechArena Community > Software > Software Development
Become a Member!
Forgot your username/password?
Register Tags Active Topics RSS Search Mark Forums Read

Sponsored Links



Search Engine through PHP

Software Development


Reply
 
Thread Tools Search this Thread
  #1  
Old 19-09-2008
Member
 
Join Date: May 2008
Posts: 2,675
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 ...

Reply With Quote
  #2  
Old 19-09-2008
Member
 
Join Date: May 2008
Posts: 2,004
You will have to add $ word = $ _POST [ 'word']
Reply With Quote
  #3  
Old 19-09-2008
Member
 
Join Date: May 2008
Posts: 2,675
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.
Reply With Quote
  #4  
Old 19-09-2008
Member
 
Join Date: May 2008
Posts: 2,289
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!
Reply With Quote
  #5  
Old 19-09-2008
Member
 
Join Date: May 2008
Posts: 2,004
You are right Zecho.

I discovered this fact. I used one of my creation but a bit old.
Thank you.
Reply With Quote
  #6  
Old 19-09-2008
Member
 
Join Date: May 2008
Posts: 2,675
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.
Reply With Quote
Reply

  TechArena Community > Software > Software Development
Tags: ,



Thread Tools Search this Thread
Search this Thread:

Advanced Search


Similar Threads for: "Search Engine through PHP"
Thread Thread Starter Forum Replies Last Post
Which is the best Web Search Engine? Maq.H Polls & Voting 7 04-12-2013 02:53 PM
Which search engine do you use? gangol Polls & Voting 1 10-08-2012 06:47 PM
in. search-results as search engine instead of Google Eseld Networking & Security 5 15-07-2011 07:23 PM
No search results found for any sex related keyword searched on Microsoft Bing Search Engine Dinsh Technology & Internet 2 27-06-2009 01:15 PM
Reliance Communications launched Quick Search new search engine on mobile Gauresh India BroadBand 0 07-11-2008 01:15 PM


All times are GMT +5.5. The time now is 11:31 PM.