|
| ||||||||||
| Tags: engine, php |
![]() |
| | Thread Tools | Search this Thread |
|
#1
| ||||
| ||||
| Search Engine through PHP
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> So if some of you have a solution. Thank you in advance ... |
|
#2
| |||
| |||
|
You will have to add $ word = $ _POST [ 'word'] |
|
#3
| ||||
| ||||
|
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
| ||||
| ||||
|
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
| |||
| |||
|
You are right Zecho. I discovered this fact. I used one of my creation but a bit old. Thank you. |
|
#6
| ||||
| ||||
|
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. |
![]() |
|
| Thread Tools | Search this Thread |
| |
Similar Threads for: "Search Engine through PHP" | ||||
| Thread | Thread Starter | Forum | Replies | Last Post |
| Which search engine do you use? | gangol | Polls & Voting | 1 | 10-08-2012 06:47 PM |
| Which is the best Web Search Engine? | Maq.H | Polls & Voting | 6 | 31-01-2012 10:16 AM |
| 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 |