Board index   FAQ   Search  
Register  Login
Board index php forum :: php coding PHP coding => General

Saving value of a drop down list using php

Ask about general coding issues or problems here.

Moderators: macek, egami, gesf

Saving value of a drop down list using php

Postby fawadmz » Wed Nov 21, 2012 12:45 am

Hello i have two pages. one have a HTML form lets say form.php . this form sends value of a drop down list (select box) to another page called getdata.php .
i can do it with other html elements but not with select box.

Would be thankful for help
fawadmz
New php-forum User
New php-forum User
 
Posts: 5
Joined: Wed Nov 21, 2012 12:15 am

Re: Saving value of a drop down list using php

Postby simplypixie » Wed Nov 21, 2012 4:47 am

Does the select allow for multiple selects? Also what is the code for your form and on the getdata.php page so we can see what you are doing (or doing wrong)?
User avatar
simplypixie
php-forum Active User
php-forum Active User
 
Posts: 300
Joined: Sun Dec 11, 2011 12:51 am
Location: Shrewsbury, Shropshire

Re: Saving value of a drop down list using php

Postby seandisanti » Fri Nov 23, 2012 2:36 pm

just make sure you're specifying values on your options and a name attribute on your select, and then it will be passed as $_POST['select_name'] or $_GET['select_name']
seandisanti
php-forum Fan User
php-forum Fan User
 
Posts: 838
Joined: Mon Oct 01, 2012 12:32 pm

Re: Saving value of a drop down list using php

Postby fawadmz » Sun Nov 25, 2012 12:58 am

Lets see if i have in form.php

<select name="search_by" >
<option value="user_name" >User Name</option>
<option value="user_id" >User Id</option>
</select>

in form.php if i want to know what value a user have selected from available options
fawadmz
New php-forum User
New php-forum User
 
Posts: 5
Joined: Wed Nov 21, 2012 12:15 am

Re: Saving value of a drop down list using php

Postby simplypixie » Sun Nov 25, 2012 1:19 am

You do it exactly the same way as you do with your other form elements (using the value posted from the form referencing the name of the form element):

Code: Select all
<?php
  $search_by = $_POST['search_by'];
?>
User avatar
simplypixie
php-forum Active User
php-forum Active User
 
Posts: 300
Joined: Sun Dec 11, 2011 12:51 am
Location: Shrewsbury, Shropshire


Return to PHP coding => General

Who is online

Users browsing this forum: Google [Bot] and 2 guests

Sponsored by Sitebuilder Web hosting and Traduzioni Italiano Rumeno and antispam for cPanel.