Please Help! How to create its own site search for a php database?

Jonathan

New member
i have two tables with listings of titles in my mysql database.
i know how to create basic form and post/get and stuff..
i created a search bar that send the input to search.php
but then i have no idea how to compare/match the data and echo out the matches... please help??

an coding example or full example would be greatly appeciated!
 
<?
if(isset($_POST['action']) && $_POST['action'] == "Search")
{
if(in_array("",$_POST))
{
die("Please give me something to search for!");
}
else
{
$search_for = mysql_real_escape_string($_POST['search_for']);
$query = mysql_query("SELECT * FROM table_name WHERE field_name LIKE '%$search_for%'");
while($info = mysql_fetch_assoc($query))
{
extract($info);
echo $field_name_as_variable . "<br>";
}
}
}
else
{
echo "<form method=\"post\" action=\"$_SERVER[PHP_SELF]\"><input type=\"hidden\" name=\"action\" value=\"Search\"><strong>Search term:</strong><input type\"text\" name=\"search_for\"><input type=\"submit\" value=\"Submit\"></form>";
}
 
<?
if(isset($_POST['action']) && $_POST['action'] == "Search")
{
if(in_array("",$_POST))
{
die("Please give me something to search for!");
}
else
{
$search_for = mysql_real_escape_string($_POST['search_for']);
$query = mysql_query("SELECT * FROM table_name WHERE field_name LIKE '%$search_for%'");
while($info = mysql_fetch_assoc($query))
{
extract($info);
echo $field_name_as_variable . "<br>";
}
}
}
else
{
echo "<form method=\"post\" action=\"$_SERVER[PHP_SELF]\"><input type=\"hidden\" name=\"action\" value=\"Search\"><strong>Search term:</strong><input type\"text\" name=\"search_for\"><input type=\"submit\" value=\"Submit\"></form>";
}
 
Back
Top