PHP Tutorials

Multiple Checkboxes

Value of multiple checkboxes in PHP

PHP Multiple Checkboxes

In this tutorial you will learn how to retrieve many values using the same checkbox name

  1. Getting multiple value using the same Check Box name.
    For example when a form contains multiple checkboxes with the same name, multiple input an be retrieved using the following PHP code.
    Your Area of Expertise:


    Your Expertise field: Java, PHP, ASP

  2. Sample PHP Code

    for($i=0;$i<$count;$i++){$strExpert="$strExpert$chkexpert[$i], ";}


    Sample HTML Code for the above example

    <form name="form1" method="post" action=""> <table width="100%" border="0" bgcolor="#D6E3F7">
    <td class="text">Your are Expertise field: </td>
    <td class="examplelink">
    <input type="checkbox" name="chkexpert[]" value="Java">
    <input type="checkbox" name="chkexpert[]" value="PHP">
    <input type="checkbox" name="chkexpert[]" value="ASP">
    <input type="checkbox" name="chkexpert[]" value=".NET">
    <input type="checkbox" name="chkexpert[]" value="JavaScript">
    <td><input type="submit" name="Submit" value="Submit">
    <input name="hidSubmit" type="hidden" id="hidSubmit2" value="true"></td>
    <td class="subtitlesmall"><p>Result:</p>
    <p><span class="reditalic">Your Expertise field: <?php echo $strExpert; ?></span></p></td>
    <td class="reditalic">&nbsp; </td>

Please like, +1, link to and share this SmartWebby resource if you found it helpful. Thanks!