Current location: Hot Scripts Forums » Programming Languages » PHP » Value from HTML drop down menu into php variable?


Value from HTML drop down menu into php variable?

Reply
  #1 (permalink)  
Old 06-09-05, 07:20 PM
flososic flososic is offline
New Member
 
Join Date: Jun 2005
Posts: 3
Thanks: 0
Thanked 0 Times in 0 Posts
Value from HTML drop down menu into php variable?

Im sure there is a simple function to do this i just do not know it. I have an html drop down menu. When the user selects an option I need to know how to tell php what option the user has selected. If there is another and better method to do this entirely im all ears. Thanks in advance.
Reply With Quote
  #2 (permalink)  
Old 06-09-05, 07:36 PM
NeverMind's Avatar
NeverMind NeverMind is offline
Community VIP
 
Join Date: Aug 2003
Location: K.S.A
Posts: 2,257
Thanks: 0
Thanked 2 Times in 1 Post
let say you have this select:
Code:
<select name="GENDER" size="1">
<option>male</option>
<option>female</option>
</select>
now after you submit the form, you can access the value submitted by:
PHP Code:

$_POST['GENDER'];//the value is stored here. 

so you access the posted date by their name like $_POST['NAME_OF_FIELD']
__________________
PHPSimplicity
We don't need a reason to help people - Zidane [FF9]
Reply With Quote
  #3 (permalink)  
Old 06-10-05, 08:56 AM
ibzi ibzi is offline
Newbie Coder
 
Join Date: Jun 2005
Posts: 39
Thanks: 0
Thanked 0 Times in 0 Posts
Don't forget, if the form's method is 'post' you need to use

PHP Code:

echo $_POST['GENDER']; 

And if it is 'get' use

PHP Code:

echo $_GET['GENDER']; 


You could always (if your PHP is updated) use this which will output it regardless of the method.

PHP Code:

echo $GENDER
__________________
--
Help us Fight SPAM!
Reply With Quote
  #4 (permalink)  
Old 06-10-05, 11:36 AM
NeverMind's Avatar
NeverMind NeverMind is offline
Community VIP
 
Join Date: Aug 2003
Location: K.S.A
Posts: 2,257
Thanks: 0
Thanked 2 Times in 1 Post
Quote:
You could always (if your PHP is updated) use this which will output it regardless of the method.
PHP Code:

echo $GENDER
this is a bad practice however! and it has nothing to do with PHP updates! it's the setting of register.global directive.
you shouldn't be lazy and use register globals! your software should know and restrict where it retraive data from $_POST or $_GET
anyway, you can use $_REQUEST array which will have the $_GET, $_POST and $_COOKIE variables inside it.
__________________
PHPSimplicity
We don't need a reason to help people - Zidane [FF9]
Reply With Quote
  #5 (permalink)  
Old 06-10-05, 10:09 PM
ElitePHP ElitePHP is offline
New Member
 
Join Date: Jun 2005
Posts: 4
Thanks: 0
Thanked 0 Times in 0 Posts
if making a $http_post_vars['FORM_NAME']; if making a public script for anything less than php4.0
Reply With Quote
  #6 (permalink)  
Old 06-11-05, 05:10 AM
NeverMind's Avatar
NeverMind NeverMind is offline
Community VIP
 
Join Date: Aug 2003
Location: K.S.A
Posts: 2,257
Thanks: 0
Thanked 2 Times in 1 Post
it's $HTTP_POST_VARS (all caps!) remember PHP is case-senstive for variables
__________________
PHPSimplicity
We don't need a reason to help people - Zidane [FF9]
Reply With Quote
Reply

Bookmarks


Currently Active Users Viewing This Thread: 1 (0 members and 1 guests)
 
Thread Tools
Display Modes

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is Off
HTML code is Off
Trackbacks are On
Pingbacks are On
Refbacks are On

Forum Jump

Similar Threads
Thread Thread Starter Forum Replies Last Post
Help with a PHP drop down menu! maweber98 PHP 5 06-01-05 04:02 PM
Please help insert html into php idforforums PHP 5 04-06-05 11:29 PM
Creating a drop down menu ? ? ? Spreegem PHP 4 03-09-05 09:34 AM
using javascript in php for image changing with drop down menu developer_x PHP 0 02-13-05 08:26 AM
drop down menu problem !!! nurqeen PHP 1 02-08-04 08:07 PM


All times are GMT -5. The time now is 06:50 AM.
vBulletin® Copyright ©2000 - 2012, Jelsoft Enterprises Ltd.