Reputation: 543
So I have a form which has a drop down list, when the submit button is pressed the script task4.php is called. My problem is that I can use the whole option that is selected, however I only need the tid. How do I get just the tid and use it task4.php?
<form action="task4.php" method="get">
<select>
<?php
foreach($results as $row) {
echo "<option>".$row[tid].", ".$row[category].", ".$row[division].", ".$row[clubID].", ".$row[name]."</option>";
}
?>
</select>
<input type ="submit" value="Submit">
</form>
This is what I've got in task 4 and it isn't working:
if (isset($_GET['tid'])) {
$tid = $_GET['tid'];
}
Upvotes: 2
Views: 41
Reputation: 219127
It's possible (perhaps even necessary) that in the absence of a value
the browser is sending the text contents of the selected option
with the form data.
Just give the option
a value
:
echo "<option value=\"".$row[tid]."\">" ...
Additionally, that select
should really have a name
(I don't even see how it could have worked without one):
<select name="tid">
Upvotes: 2