0

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

2 Answers 2

1

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']
Sign up to request clarification or add additional context in comments.

1 Comment

Thank for your promt help. That's what I need exactly. You are the best.
0

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'];

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.