Ok, so I will do my best at explaining this...
I have set up a database of our company's Parts Ordered forms.
I have created a php form that allows users to inject new POs into the database. Which works successfully.
I am working on the search form to allow users to search for a certain PO base on one of the following criteria: PO Number, Date, or VIN Number.
I am trying to find the best way to allow users to search by date. Since I used the MYSQL function CURDATE(), it is stored as 2010-10-10. What would be the easiest way to allow users to search by this. I know i could use drop down fields in my form but i don't know how to modify my php code for that to work.... here is what i have so far:
Note that if I choose to search by date that i have to enter it in the exact format...xxxx-xx-xx. - I want to make it easy for the user by having drop down fields to select the year, day, and month...any help is appreciated!
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
<html xmlns="http://www.w3.org/1999/xhtml">
<html>
<head>
<title>Search the Database</title>
</head>
<body>
<form method="POST" action="<?php echo $_SERVER['PHP_SELF']; ?>">
Search: <select name="type">
<option value='po_num' selected>PO Number</option>
<option value='date'>Date</option>
<option value='vin_num'>VIN Number</option>
</select>
for: <input type="text" name="term" /><br />
<input type="submit" name="submit" value="submit" />
</form>
</body>
</html>
<?php
$term = $_POST['term'];
if ($term == '')
{
echo 'Please enter a value.';
exit;
}
$search_result = '';
if (isset($_POST['submit'])) {
mysql_connect ("localhost", "user","pass") or die (mysql_error());
mysql_select_db ("inventory");
$type = $_POST['type'];
$term = $_POST['term'];
$safetype = mysql_real_escape_string($_POST['type']);
$safeterm = mysql_real_escape_string($_POST['term']);
$sql = mysql_query("select * from partsorder where $type like '%$term%'");
while ($row = mysql_fetch_array($sql)){
//var_dump($row);
$search_result .= '<br/> <B>PO Number:</B> '.$row['po_num'] . "\n";
$search_result .= '<br/><B> Date:</B> '.$row['date'] . "\n";
$search_result .= '<br/><B> VIN Number:</B> '.$row['vin_num'] . "\n";
$search_result .= '<br/> <B>Description:</B> '.$row['para'] . "\n";
$search_result .= '<br/> <B>Purchase Agent:</B> '.$row['purch_agt'] . "\n";
$search_result .= '<br/><br/>' . "\n";
}
}
echo $search_result;
?>