Reputation: 49
how post/get hidden value (id) from dynamic drop-down menu?
<select name="motinine">
$query=mysql_query("SELECT id, Name FROM mothebord ORDER BY name");
<?php
while($row = mysql_fetch_assoc($query))
{
$pav =$row['Name'];
echo "<option>$pav</option>";
}
?>
Upvotes: 1
Views: 2444
Reputation: 15106
Place the id in the value attribute of the options.
echo '<option value="'.$row["id"].'">'.$pav.'</option>';
Give the select a name.
<form action="process.php" method="post">
<select name="motherboard">
<option value="1">Name1</option>
<option value="2">Name2</option>
<option value="3">Name3</option>
</select>
<input type="submit" />
</form>
And retrieve it in your php file using $_POST
or $_GET
depending on the method
, or simply $_REQUEST
.
$_POST["motherboard"] // contains the selected value
Upvotes: 2
Reputation: 23379
You need to give your option a value
echo "<option value='$pav'>$pav</option>";
Then you can retrieve the data with
$_POST['motinine']
if using POST
$_GET['motinine']
if using GET
or
$_REQUEST['motinine']
with either one.
Upvotes: 1