Need help creating a simple search form

admin

Administrator
Staff member
Hi,
I'm a newbie to PHP so forgive me if this is very simple. I've tried and tried to get this to work on my own to no avail and I've tried all kinds of code posted here, but I just don't understand enough to get it working.

I have a MySQL db with a table named 'example'. It has three columns or fields: 'name', 'birth' and 'death'.

I want to create an HTML form that has a search box and a drop down list that let's the user choose which field he/she will search on. i.e. They can choose to search for the name of a person, the year a person died or the year a person was born.

Can someone please point me to an example of how this would work? I was able to create a simple page that displayed the whole database listings with this code:

<?php include("dbconnect.php"); ?>

<h2>View Whole Database</h2>

<?php

$result = mysql_query("select * from "example");
if ($result)
{
while ($row = mysql_fetch_array($result))
{
print "<b>Name:</b>";
print $row["name"];
print "<br>\n";
print "<b>Birth:</b>";
print $row["birth"];
print "<br>\n";
print "<b>Death:</b>";
print $row["death"];
print "<br>\n";
print "<br>\n";
print "<br>\n";
}
mysql_free_result($result);
}
?>

But I have no idea how to create a frontend search form that would allow the user to "choose" which field he would like presented and then search only on that field. Can someone PLEASE help me! :-)

Thanks,
Joe
 
Back
Top