Solved

Retruve the multiple value from the select multiple tag in PHP

Posted on 2004-04-06
4
235 Views
Last Modified: 2010-04-17
Hi Experts,

    I have an html file which has a select tag with multiple selection and i want to get the selected multiple value from that html file to the php file

 html file is as follows

<html>
<body>
<select name = "option" multiple>
<option>one</option>
<option>two</option>
<option> three</option>
</select>
</body>
</html>

PHP file is as follows

<?php

    $selectvalue = $_POST['option'];

?>

but in this php file i'm getting only one value and i'm nit getting multiple value.

Please help me out to solve this .
 or give me some example that would help me out

Thanx

0
Comment
Question by:mohan21_kumar
4 Comments
 
LVL 1

Expert Comment

by:gourav_jain
ID: 10772489
Hi,

use @selectvalue = $_POST['option'] instead, this will give you the array of all the values of your form variable "option".

Gourav Jain
0
 
LVL 28

Accepted Solution

by:
peakpeak earned 25 total points
ID: 10772636
In the form definition you need brackets after the name to define an array

<select name="option[]" multiple>

In the php script you then extract the values as follows:

<?php
$option = $_POST['option'];
foreach($option as $selected)
{
        print $selected." / ";
}       
?>

Regards
Peter
0

Featured Post

Announcing the Most Valuable Experts of 2016

MVEs are more concerned with the satisfaction of those they help than with the considerable points they can earn. They are the types of people you feel privileged to call colleagues. Join us in honoring this amazing group of Experts.

Question has a verified solution.

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

Suggested Solutions

A short article about a problem I had getting the GPS LocationListener working.
This article will inform Clients about common and important expectations from the freelancers (Experts) who are looking at your Gig.
An introduction to basic programming syntax in Java by creating a simple program. Viewers can follow the tutorial as they create their first class in Java. Definitions and explanations about each element are given to help prepare viewers for future …
With the power of JIRA, there's an unlimited number of ways you can customize it, use it and benefit from it. With that in mind, there's bound to be things that I wasn't able to cover in this course. With this summary we'll look at some places to go…

813 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

13 Experts available now in Live!

Get 1:1 Help Now