Solved

could not get all selected values from list box (multiple)

Posted on 2006-07-09
4
1,203 Views
Last Modified: 2012-06-27
I am using PHP5, my problem is i did get all selected valuse from the list box. once i submit the form i did get all selected values from the list box.
if i say       echo $_POST['jobsector'; I am geting only one value for example if select all three valuse from the list box i am getting only last value. pls help me.

echo "<form action='registration.php' method=POST ENCTYPE='multipart/form-data'>";
echo "<table><tr><td  >  Preferred Job Sector * </td>";
      echo "    <td WIDTH='58%' VALIGN=TOP>
      <Select Size=4 Multiple name='jobsector'>
            <option value='Administration'>Administration</option>
            <option value='Commercial Management'>Commercial Management</option>
            <option value='Corporate Affairs'>Corporate Affairs</option>
       </Select></td></tr>";
echo "<tr><td ><INPUT TYPE='submit' name='submit' value='submit'></td>";
      echo "</tr></table>";
echo "</form>";
0
Comment
Question by:jessi_vs
  • 2
4 Comments
 
LVL 29

Assisted Solution

by:TeRReF
TeRReF earned 25 total points
ID: 17070827
Change this:
    <Select Size=4 Multiple name='jobsector'>
to
    <Select Size=4 Multiple name='jobsector[]'>

Now it's an array with all selected values:
print_r($_POST['jobsector']);
0
 
LVL 2

Accepted Solution

by:
arun80_inin earned 25 total points
ID: 17071042
If you are using multiple select box the name should be end with []
ex:jobsector[]

If you give the name like this then you can use the following code in php to get all the values

for (i=0;i<count($_POST['jobsector'];$i++)
{
     echo $_POST['jobsector'][$i];
}
0
 
LVL 29

Expert Comment

by:TeRReF
ID: 17071074
That's pretty much what I said :)
0
 

Author Comment

by:jessi_vs
ID: 17071224
TeRReF's command is good enough to solve my problem. arun's comment is very informative. Thank you all.
0

Featured Post

Netscaler Common Configuration How To guides

If you use NetScaler you will want to see these guides. The NetScaler How To Guides show administrators how to get NetScaler up and configured by providing instructions for common scenarios and some not so common ones.

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

This article will explain how to display the first page of your Microsoft Word documents (e.g. .doc, .docx, etc...) as images in a web page programatically. I have scoured the web on a way to do this unsuccessfully. The goal is to produce something …
Part of the Global Positioning System A geocode (https://developers.google.com/maps/documentation/geocoding/) is the major subset of a GPS coordinate (http://en.wikipedia.org/wiki/Global_Positioning_System), the other parts being the altitude and t…
The viewer will learn how to dynamically set the form action using jQuery.
The viewer will learn how to count occurrences of each item in an array.

770 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question