hi im attempting to keep a group of tick boxes ticked after i refresh the browser in been through the forums trying different solutions but anything ive tried doesnt work if anyone has a solution to this be much grateful


include ('connect.php');

<div class="main">
            <h2>PHP: Get Values of Multiple Checked Checkboxes</h2><hr/>
            <form action="php_checkbox.php" method="post">
            <label class="heading">Select Your Technical Exposure:</label><br/><br/>
            <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="checkbox" name="check_list[]" value="HTML/CSS"><label>HTML/CSS</label><br/>
            <input type="checkbox" name="check_list[]" value="UNIX/LINUX"><label>UNIX/LINUX</label><br/><br/>
            <input type="submit" name="submit" Value="Submit"/>
            <!-----Including PHP Script----->
            <?php include 'checkbox_value.php';?>

processing form

include ('connect.php');
    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>";

ty jan

Recommended Answers

All 8 Replies

after googling i have done the following but have encountered a error see below:
Warning: in_array() expects parameter 2 to be array, null given in /home/jktempla/public_html/sample/index.php on line 19


<input type="checkbox" name="hobbies[]" value="Playing" <?php echo (in_array('Playing',$hobbies)) ?'checked':'' ?> ><label>Playing</label><br/>
 <input type="checkbox" name="hobbies[]" value="Coding" <?php echo (in_array('Coding',$hobbies)) ?'checked':'' ?> ><label>Coding</label><br/>
 <input type="checkbox" name="hobbies[]" value="Reading" <?php echo (in_array('Reading',$hobbies)) ?'checked':'' ?> ><label>Reading</label><br/>
 <input type="checkbox" name="hobbies[]" value="Hacking" <?php echo (in_array('Hacking',$hobbies)) ?'checked':'' ?> ><label>Hacking</label><br/>
 <input type="checkbox" name="hobbies[]" value="Playing" <?php echo (in_array('Sleeping',$hobbies)) ?'checked':'' ?> ><label>Sleeping</label>

ive check all values and names correct can anyone tell me what im missing

much appreciated

Heres the code hun


 if(!empty($_POST['hobbies'])) {

 if(empty($_POST['hobbies']) || count($_POST['hobbies']) < 2)
    $hobbies_error = "Please select at least 2 items for your hobbies";
$hobbies = $_POST['hobbies'];

 //Loop through hobbies array to fetch individual hobby so that we can use them
 echo "<h2> You have selected: </h2>";
 foreach($_POST['hobbies'] as $hobby) {
 echo "<p>".$hobby ."</p>"; //Print all the hobbies

/* Alert hobbies using JS
$show = "<p>".$hobby ."</p>";
echo "<script type='text/javascript'>alert(\"Your Hobbies are: '$show'\");</script>";

 echo "<b>Please Select at least One Hobby.</b>";

Can't see where $hobby or $hobbies array is declared. What line is that on?

i dont think its one got the script from search engines hun ill sort it now x

sorted that but now when i select any items they are not echoing through x

sorted now :)

ty all for your help

Be a part of the DaniWeb community

We're a friendly, industry-focused community of developers, IT pros, digital marketers, and technology enthusiasts meeting, learning, and sharing knowledge.