top of page

Retrieve multiple selected values using PHP

While storing values selected by user in database only one value is stored.

This post describes how to retrieve multiple values selected by user from checkbox using PHP.

How to sent multiple values from checkbox in HTML to action url :

You just need to add attribute name as an array(eg : name=language[]) in checkbox in order to sent multiple values.

 

Skills :

<input type = "checkbox" name = "skills[]" value="Java"//> Java

<input type = "checkbox" name = "skills[]" value="C"//> C

<input type = "checkbox" name = "skills[]" value="C++"//> C++

<input type = "checkbox" name = "skills[]" value="Web

Output :

 

Retrieve multiple selected values from checkbox box using PHP

To get multiple values selected by user use $_POST['selection_box_name'] ( if form method is post) in PHP.

 

Example :

$skills=$_POST["skills"]; (All values selected by user is stored in $skills variable to get individual value use for loop)

foreach($skills as $val) { echo $val.'<br>'; }

(prints each individual value, For every loop iteration, the value of the current array element(i.e. skills) is assigned to $value and the array pointer is moved by one, until it reaches the last array element)

Featured Posts
Recent Posts
Archive
Search By Tags
No tags yet.
Follow Us
  • Facebook Basic Square
  • Twitter Basic Square
  • Google+ Basic Square
bottom of page