0

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

4
Contributors
4
Replies
5
Views
7 Years
Discussion Span
Last Post by pravinkumarr
0

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.

0

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;
		}
?>
0

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

This topic has been dead for over six months. Start a new discussion instead.
Have something to contribute to this discussion? Please be thoughtful, detailed and courteous, and be sure to adhere to our posting rules.