i have a simple drop down select menu.
<div id="select">
<select class="select">
<option value="year 1">year 1</option>
<option value="year 2">year 2</option>
<option value="year 3">year 3</option>
</select>
</div>
How do i take the value that the user selects and store it into a php variable?
in somephpfile.php
$selected = $_POST['somename'];
html
<form action="somephpfile.php" method="post">
<div id="select">
<select class="select">
<select name="somename"> <!-- you missed this -->
<option value="year 1">year 1</option>
<option value="year 2">year 2</option>
<option value="year 3">year 3</option>
</select>
</div>
</form>
you missed the "name" attribut in the select and the form tag. Try this:
<HTML><BODY>
<?PHP
$sel_year= $_POST['select'];
echo $sel_year
?>
<FORM method="post" action="...your-php-file-name-here...">
<div id="select">
<select name="select">
<option value="year 1">year 1</option>
<option value="year 2">year 2</option>
<option value="year 3">year 3</option>
</select>
</div>
</FORM>
</BODY></HTML>
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With