- Impact
- 9
OK This tutorial will show you how to make a search page.
Firstly we make a form. I am going to use this:
This is the form where we will enter the keywords. Now the next step is to make the searchpage.php.
It will look like this
Firstly we make a form. I am going to use this:
PHP:
<form method="post" action="searchpage.php">
<p>Please enter keyword.</p>
<p>
<input name="word" type="text" size=25 maxlength=25>
</p>
<p>
<input type="Submit" name="Submit" value="Submit">
</p>
</form>
It will look like this
PHP:
<?php
// connect to db
$db = mysql_connect("localhostt", "username", "password");
mysql_select_db("dbname",$db);
//check something is sent
if ($_POST['word']) {
$word= $_POST["word"];
// search query
$result = mysql_query("SELECT * FROM `table` WHERE `field` LIKE '%$word%'");
$postword = $_POST['word'];
echo "Search Results for: <strong> $postword </strong> <br />";
echo"<p> </p>";
echo"<p> </p>";
echo"<p> </p>";
echo"<p> </p>";
//get results
while($get=mysql_fetch_array($result))
{
$date = $get['date'];
$name = $get['name'];
$title= $get['title'];
//show results
echo("<strong>$title</strong> was added on <strong>$date</strong> by <strong>$name</strong>");
echo"<p></p>";
echo"<p></p>";
}
// if nothing is sent
}else {
die ("No search word specified");
}
?>






