Following on from a recent post.
I am creating a search function that queries a SQL database. The database consists of different types of meat packaging. I have created HTML & PHP code that will search the database and display results using only one form and submit button. But I now want to create a search box that has multiple forms (including three dropdown ones), that when users type in sizes, click a dropdown and type in a id code, they can submit using one submit button and then will be referred to a page that consists of the results that match all three combined.
Can anyone give me some insight about how to go about this? I have tried creating two forms that submit to the same PHP page for results, but one seems to override the other.
Here is my HTML and PHP code currently:
<body>
<form action="form2.php" method="post">
Search: <input type="text" name="term" /><br />
<input type="submit" value="Submit" />
</form>
</body>
And the PHP code:
<body>
<?php
$con = mysql_connect ("localhost", "root", "");
mysql_select_db ("delyn_db", $con);
if (!$con)
{
die ("Could not connect: " . mysql_error());
}
$term = mysql_real_escape_string($_REQUEST['term']);
$sql = "SELECT * FROM delyn WHERE toolcode LIKE '%".$term."%' OR trayheight LIKE
'%".$term."%' OR delyncode LIKE '%".$term."%' OR description LIKE '%".$term."%'
OR trayshape LIKE '%".$term."%' OR traydepth LIKE '%".$term."%' OR traywidth
LIKE '%".$term."%'";
$r_query = mysql_query($sql);
if(!$sql)
{
echo "could not find";
}
while ($row = mysql_fetch_array($r_query)){
echo 'ID: ' .$row['ID'];
echo '<br /> Delyn code: ' .$row['delyncode'];
echo '<br /> Tool Code: '.$row['toolcode'];
echo '<br /> Description: '.$row['description'];
echo '<br /> Tray range '.$row['trayrange'];
echo '<br /> Tray type: '.$row['traytype'];
echo '<br /> Tray size: '.$row['traysize'];
echo '<br /> Tray height: '.$row['trayheight'];
echo '<br /> Tray width: '.$row['traywidth'];
echo '<br /> Tray depth: '.$row['traydepth'];
echo '<br /> Tray shape: '.$row['trayshape'];
echo '<br /> imagename: '.$row['imagename'];
echo '<br /> Tray live: '.$row['traylive'] . ' <br /><br />';
}
?>
</body>
Thanks in advance :)
Edited php:
<body>
<?php
$con = mysql_connect ("localhost", "root", "");
mysql_select_db ("delyn_db", $con);
if (!$con)
{
die ("Could not connect: " . mysql_error());
}
if(isset($_POST['formSubmit']) )
{
$varType = $_POST['traytype'];
}
$term = mysql_real_escape_string($_POST['term']);
$sql = "SELECT * FROM delyn WHERE traytype LIKE '%".$varType."%'";
$r_query = mysql_query($sql);
while ($row = mysql_fetch_array($r_query)){
echo 'ID: ' .$row['ID'];
echo '<br /> Delyn code: ' .$row['delyncode'];
echo '<br /> Tool Code: '.$row['toolcode'];
echo '<br /> Description: '.$row['description'];
echo '<br /> Tray range '.$row['trayrange'];
echo '<br /> Tray type: '.$row['traytype'];
echo '<br /> Tray size: '.$row['traysize'];
echo '<br /> Tray height: '.$row['trayheight'];
echo '<br /> Tray width: '.$row['traywidth'];
echo '<br /> Tray depth: '.$row['traydepth'];
echo '<br /> Tray shape: '.$row['trayshape'];
echo '<br /> imagename: '.$row['imagename'];
echo '<br /> Tray live: '.$row['traylive'] . ' <br /><br />';
}
?>
</body>