Solved

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

Posted on 2006-07-09
4
1,204 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

Networking for the Cloud Era

Join Microsoft and Riverbed for a discussion and demonstration of enhancements to SteelConnect:
-One-click orchestration and cloud connectivity in Azure environments
-Tight integration of SD-WAN and WAN optimization capabilities
-Scalability and resiliency equal to a data center

Question has a verified solution.

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

Suggested Solutions

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 …
This article discusses how to create an extensible mechanism for linked drop downs.
Learn how to match and substitute tagged data using PHP regular expressions. Demonstrated on Windows 7, but also applies to other operating systems. Demonstrated technique applies to PHP (all versions) and Firefox, but very similar techniques will w…
The viewer will learn how to create a basic form using some HTML5 and PHP for later processing. Set up your basic HTML file. Open your form tag and set the method and action attributes.: (CODE) Set up your first few inputs one for the name and …

856 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