Solved

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

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

What Security Threats Are You Missing?

Enhance your security with threat intelligence from the web. Get trending threat insights on hackers, exploits, and suspicious IP addresses delivered to your inbox with our free Cyber Daily.

Join & Write a Comment

Developers of all skill levels should learn to use current best practices when developing websites. However many developers, new and old, fall into the trap of using deprecated features because this is what so many tutorials and books tell them to u…
These days socially coordinated efforts have turned into a critical requirement for enterprises.
Explain concepts important to validation of email addresses with regular expressions. Applies to most languages/tools that uses regular expressions. Consider email address RFCs: Look at HTML5 form input element (with type=email) regex pattern: T…
The viewer will learn how to count occurrences of each item in an array.

757 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

Need Help in Real-Time?

Connect with top rated Experts

20 Experts available now in Live!

Get 1:1 Help Now