Saving the value from a drop-down list
36,622
Solution 1
Its two step: First html:
<form action='databasethings.php' method=post>
<select name="myvalue">
<option value="value1">Value 1</option>
<option value="value2">Value 2</option>
<option value="value3">Value 3</option>
</select>
<input type=submit>
</form>
Its for sending the value to databasethings.php script.(
Then in databasethings.php:
$myvalue=$_POST['myvalue'];
//do something with myvalue
This will catch value1, 2 or 3 from html into $myvalue in php
Solution 2
HTML:
<form action="page.php" method="get">
<select id="drop" name="drop">
<option value="Volvo">Volvo</option>
<option value="Saab">Saab</option>
<option value="Mercedes">Mercedes</option>
<option value="Audi">Audi</option>
</select>
<input type="submit" value="Submit!">
</form>
page.php:
<?php
echo $_GET['drop'];
?>
Author by
DogPooOnYourShoe
Updated on August 26, 2020Comments
-
DogPooOnYourShoe over 3 years
Here's my situation, I have 2 pages, one for selecting a value and one for editing database related things which are associated to that value.
Right now, I have no knowledge ( and have researched a fair bit ) on how to save the value selected from the drop down list into a variable from PHP.
Any ideas?