In my drop down list, each row has 3 fields from a db. I somehow need to pass these to another form where I will reference them in another SQL statement.
I’m not sure how to pass them. Any help would be really appreciated.
<form action='obtainaprice.php' method='POST'>
<?php
echo "<select name='makes' id='searchtext'>\n";
$query1 = "SELECT DISTINCT make, type, model FROM device ORDER BY make, type, model";
$result1 = mysql_query($query1)
or die ("Couldn't execute query.");
while ($row1 = mysql_fetch_array($result1))
{
$i=0;
echo "<option value= \"" . $i . "\">" . $row1['make'] . " " . $row1['type'] . " " . $row1['model'] . "</option>";
$i++;
}
echo "</select>\n";
?>
<input type="image" id="buttons" alt="Search" img src="images/button.png">
</form>
In this case you would make the value of the options the row’s id, which you need to select:
assuming your primary index is called id…
Then on your next page you would run the next query based on the post value for makes…
of course, you need to sanitize this. You should switch to mysqli or PDO.
Side note – you should break out of php for writing html. It’s just cleaner. Run your query first so you don’t die in the middle of a select box. I don’t condone use of mysql_ functions but for the sake of example here is what I mean…