<html>
<body>
Search:
<form method='post' action='search.php'>
<input type='text' name='search' size='25' maxlength='25'>
<input type='Submit' name=' Search ' value='Submit'>
</form>
</body>
</html>
//search.php page
<?php
$host="Host";
$username="Username";
$password="Password";
$db_name="Database Name";
$tbl_name="Table Name";
mysql_connect("$host", "$username", "$password")or die("Cannot connect");
mysql_select_db("$db_name")or die("Cannot select database");
$search=$_POST["search"];
search
$result = mysql_query("SELECT * FROM $tbl_name WHERE name LIKE '%$search%'");
while($r=@mysql_fetch_array($result))
{
//change the names to your columns
$topic=$r["topic"];
$message=$r["message"];
$name=$r["name"];
$date=$r["date"];
$id=$r["id"];
//display the row
echo "<b>$id</b> | <b>$topic</b> by <b>$name</b> at <b>$date</b><br><br>$message";
}
if(!search){
echo "Please enter a search.";
}
else
{
echo "Sorry, there were no searches with the criteria of <b>$search</b>.";
}
?>
No comments:
Post a Comment