1

I can handle multiple checkbox easily but i got problem at unchecked checkbox.

Here the thing.

I 3 checkbox.

$resultValue = "BLA BLA";
//where BLA BLA is the query process

<div class="checkbox">
    <label>
        <?php
        if ($resultValueI['keyboard'] == TRUE)
        {
        ?>
            <input name="checkbox[]" value="keyboard" type="checkbox" class="ace" checked="checked"/>
        <?php
        }
        else
        {
        ?>
            <input name="checkbox[]" value="keyboard" type="checkbox" class="ace" />
        <?php
        }
    ?>
        <span class="lbl"> Keyboard</span>
    </label>
</div>

<div class="checkbox">
    <label>
        <?php
        if ($resultValueI['mouse'] == TRUE)
        {
        ?>
            <input name="checkbox[]" value="mouse" type="checkbox" class="ace" checked="checked"/>
        <?php
        }
        else
        {
        ?>
            <input name="checkbox[]" value="mouse" type="checkbox" class="ace" />
        <?php
        }
    ?>
        <span class="lbl"> Mouse</span>
    </label>
</div>

<div class="checkbox">
    <label>
        <?php
        if ($resultValueI['battery'] == TRUE)
        {
        ?>
            <input name="checkbox[]" value="battery" type="checkbox" class="ace" checked="checked"/>
        <?php
        }
        else
        {
        ?>
            <input name="checkbox[]" value="battery" type="checkbox" class="ace" />
        <?php
        }
    ?>
        <span class="lbl"> Battery</span>
    </label>
</div>

Checkbox will checked if the info from database is TRUE, and unchecked when info from database is FALSE.

to update the record i need to do the POST method,

if (isset($_POST['checkbox']))
{
    $checkbox = $_POST['checkbox'];
    $count = count($checkbox);
}

for ($i = 0; $i < $count; $i++)
{
    //UPDATE record to TRUE magic happen here           
}

When click the submit button, i only get value the CHECKED value, how about the unchecked value, how to update record to FALSE when the checkbox is unchecked?

Asyraf
  • 31
  • 9

0 Answers0