Hi, I am somewhat new to PHP and having a bit of trouble figuring out how to grab the value from a drop down menu from a form. Also I want to assign a number to the selected option. For Example, the person will select computer memory from the drop down menu and when they click the submit button it will echo the selected memory and the price. Whats the best way to do this? Thank You

Recommended Answers

All 4 Replies

Hi,

<?php
		if(isset($_REQUEST['send']))
		{
			$mydrodown = $_REQUEST['mydrodown'];
			echo "You have selected ".$mydrodown." from drop down.";
			exit;
		}
?>
<form id="form1" name="form1" method="post" action="">	
	<select name="mydrodown">
		<option value="computer memory">computer memory</option>
		<option value="computer parts">computer parts</option>
		<option value="computer peripherals">computer peripherals</option>
	</select>	
	
	<input name="send" value="send" type="submit" />
</form>

Here i have given example of dropdown named 'mydrodown'.
You can give as many option field as you want.
once your form is submitted you can retrieve its value by $_REQUEST or $_POST and can use that variable.

hope this will help you.

Member Avatar for rajarajan2017

Adding some info with the above code, if you have price in your sql table then

<?php
		if(isset($_REQUEST['send']))
		{
			$mydrodown = $_REQUEST['mydrodown'];
			echo "You have selected ".$mydrodown." from drop down.";
//Establish the connection to the database
//Make query to select the price based on the $_REQUEST['mydrodown'];
//Display the price with the item selected.

			exit;
		}
?>

Thank You for the helpful knowledge, I was able to use the php code to do what I wanted. But I am having a little trouble with MySQL. What I want to do is assign a cell for each option selected and a price or insert the price into my sql table depending on the option selected. Whichever is easier or more sufficient. Then when you click the recalculate button it will add them all up and echo the total. Whats the best way to do this? Here is the form:


http://illcomputers.comyr.com/custom.php

can use update command with the primary key to all the fields in it i think.

Be a part of the DaniWeb community

We're a friendly, industry-focused community of developers, IT pros, digital marketers, and technology enthusiasts meeting, networking, learning, and sharing knowledge.