Reputation: 3
I need a help again.
I need to solve the next problem.
I have to fill one dropdown list from database. If the user select one value, and press the submit button, I have to send the user to the next page, and I should show for all details from this selected value.
Like if the selected value is Monitor, on the next page I have to show the price,and product name and etc in one table.
But I can't figure out how can I get the selected value from this dropdown list and what I should do. This is my code, what is generate my dropdown list and working well.
<?php
mysql_connect("localhost", "root","") or die(mysql_error());
mysql_select_db("efszf_a") or die(mysql_error());
$query = "SELECT nev FROM tanulok";
$result = mysql_query($query) or die(mysql_error()."[".$query."]");
?>
<select name="tanulok">
<?php
while ($row = mysql_fetch_array($result))
{
echo "<option value=".$row['nev'].">".$row['nev']."</option>";
}
?>
</select>
Please help me. Regards
Upvotes: 0
Views: 952
Reputation: 2397
You need to put your select inside of a form, and have the form submission point to your next page. Like:
<form action='[yourNextPage.php]' method='post'>
<select name="tanulok">
<?php
while ($row = mysql_fetch_array($result))
{
echo "<option value=".$row['nev'].">".$row['nev']."</option>";
}
?>
</select>
<input type='submit' value='Submit'>
</form>
Then in your next page, you can access the value the user selected through the $_POST array, like:
$_POST['tanulok']
Upvotes: 1
Reputation: 3131
Hi if your using post in php you will be able to get the value of the select option by using the select name like this
$theSelectValue = $_POST['tanulok'];
Upvotes: 0