Thursday, 10 March 2016

How to get Multiple Checkbox values in php

In this tutorial we are going to learn how to get Multiple Checkbox values in php. This is very simple things every experienced programmer know this things but If new programmer don't know this things. This tutorial is for beginner php programmer. In php , If we want get the single value of checkbox then it simply get by post method but problem is there if we want get the values from multiple checkbox then at that time problem occur. This things is done by define multiple checkbox with same name with array and then after use foreach to fetch all values of checkbox.

Source Code

           <title>Webslesson Tutorial</title>  
           <h3>Please Select Programming Language</h3>  
           <form method="post">  
                <p><input type="checkbox" name="language[]" value="C" /> C</p>  
                <p><input type="checkbox" name="language[]" value="C++" /> C++</p>  
                <p><input type="checkbox" name="language[]" value="C#" /> C#</p>  
                <p><input type="checkbox" name="language[]" value="Java" /> Java</p>  
                <p><input type="checkbox" name="language[]" value="PHP" /> PHP</p>  
                <p><input type="submit" name="submit" value="Submit" />  
           echo '<h3>You have select following language</h3>';  
           foreach($_POST["language"] as $language)  
                echo '<p>'.$language.'</p>';  
           echo "Please Select Atleast one Programming language";  


Post a Comment