Solved

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

Posted on 2006-07-09
4
1,206 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
[X]
Welcome to Experts Exchange

Add your voice to the tech community where 5M+ people just like you are talking about what matters.

  • Help others & share knowledge
  • Earn cash & points
  • Learn & ask questions
  • 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

Industry Leaders: We Want Your Opinion!

We value your feedback.

Take our survey and automatically be enter to win anyone of the following:
Yeti Cooler, Amazon eGift Card, and Movie eGift Card!

Question has a verified solution.

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

Suggested Solutions

Title # Comments Views Activity
Help with mod_substitute 18 76
Compiling PHP with Curl plus protocols 8 48
Bootstrap - BootBox - PHP - MYSQL - Response Trigger 6 59
history of pages 7 51
Author Note: Since this E-E article was originally written, years ago, formal testing has come into common use in the world of PHP.  PHPUnit (http://en.wikipedia.org/wiki/PHPUnit) and similar technologies have enjoyed wide adoption, making it possib…
Since pre-biblical times, humans have sought ways to keep secrets, and share the secrets selectively.  This article explores the ways PHP can be used to hide and encrypt information.
The viewer will learn how to count occurrences of each item in an array.
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 …

734 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