In our previous tutorials, we have performed various operations on different form elements using Javascript and jQuery. In this tutorial, our concern is to get values of multiple checked checkboxes using PHP as follows:

 To get  value of a checked checkbox :

<form action="#" method="post">
<input type="checkbox" name="gender" value="Male">Male</input>
<input type="checkbox" name="gender" value="Female">Female</input>
<input type="submit" name="submit" value="Submit"/>
if (isset($_POST['gender'])){
echo $_POST['gender']; // Displays value of checked checkbox.

To get value of multiple checked checkboxes, name attribute in HTML input type=”checkbox” tag must be initialize with an array, to do this write [ ] at the end of it’s name attribute :

<form action="#" method="post">
<input type="checkbox" name="check_list[]" value="C/C++"><label>C/C++</label><br/>
<input type="checkbox" name="check_list[]" value="Java"><label>Java</label><br/>
<input type="checkbox" name="check_list[]" value="PHP"><label>PHP</label><br/>
<input type="submit" name="submit" value="Submit"/>
if(isset($_POST['submit'])){//to run PHP script on submit
// Loop to store and display values of individual checked checkbox.
foreach($_POST['check_list'] as $selected){
echo $selected."</br>";

In our example, there is a form contains some checkboxes, User checks them and when he/she hits submit button, multiple values of checkboxes will be display.

Watch our live demo or download our codes to use it.

[dlv dl_url=”” dl_text =”Download script” lv_url=”” lv_text=”Live Demo” prev_domain=”mailget” prev_first=”” prev_second=”” prv_btn_text=”” prv_btn_link=””]

Our example’s complete HTML and PHP codes are given below.

HTML Codes: php_checkbox.php
Given below our complete HTML codes.

<!DOCTYPE html>
<title>PHP: Get Values of Multiple Checked Checkboxes</title>
<link rel="stylesheet" href="css/php_checkbox.css" />
<div class="container">
<div class="main">
<h2>PHP: Get Values of Multiple Checked Checkboxes</h2>
<form action="php_checkbox.php" method="post">
<label class="heading">Select Your Technical Exposure:</label>
<input type="checkbox" name="check_list[]" value="C/C++"><label>C/C++</label>
<input type="checkbox" name="check_list[]" value="Java"><label>Java</label>
<input type="checkbox" name="check_list[]" value="PHP"><label>PHP</label>
<input type="checkbox" name="check_list[]" value="HTML/CSS"><label>HTML/CSS</label>
<input type="checkbox" name="check_list[]" value="UNIX/LINUX"><label>UNIX/LINUX</label>
<input type="submit" name="submit" Value="Submit"/>
<!----- Including PHP Script ----->
<?php include 'checkbox_value.php';?>

PHP Codes: checkbox_value.php

In the below script, we used foreach loop to display individual value of checked checkboxes, we have also used a counter to count number of checked checkboxes.

if(!empty($_POST['check_list'])) {
// Counting number of checked checkboxes.
$checked_count = count($_POST['check_list']);
echo "You have selected following ".$checked_count." option(s): <br/>";
// Loop to store and display values of individual checked checkbox.
foreach($_POST['check_list'] as $selected) {
echo "<p>".$selected ."</p>";
echo "<br/><b>Note :</b> <span>Similarily, You Can Also Perform CRUD Operations using These Selected Values.</span>";
echo "<b>Please Select Atleast One Option.</b>";

CSS File: php_checkbox.css

Styling HTML elements.

/* Below line is used for online Google font */
@import url(;
width: 960px;
height: 610px;
margin:50px auto;
font-family: 'Droid Serif', serif;
width: 308px;
margin-top: 35px;
border-radius: 5px;
Border:2px solid #999900;
padding:0px 50px 20px;
margin-top: 5px;
margin-bottom: 5px;
font-weight: bold;
background-color: #FEFFED;
padding: 25px;
margin: 0 -50px;
text-align: center;
border-radius: 5px 5px 0 0;
margin: 0 -50px;
border: 0;
border-bottom: 1px solid #ccc;
color: #464646;
text-shadow: 0 1px 0 #fff;
font-size: 14px;
font-weight: bold;
font-size: 17px;
margin-right: 10px;
padding: 10px;
text-align: center;
font-size: 18px;
background: linear-gradient(#ffbc00 5%, #ffdd7f 100%);
border: 2px solid #e5a900;
color: #ffffff;
font-weight: bold;
cursor: pointer;
text-shadow: 0px 1px 0px #13506D;
width: 100%;
border-radius: 5px;
margin-bottom: 15px;
background: linear-gradient(#ffdd7f 5%, #ffbc00 100%);

Once you got the value of checked checkbox(es), you can also perform CRUD (Create, Read, Update & Delete) operations in database. Hope you like it, keep reading our other blogs.