简体   繁体   中英

Retaining check box values after the form is submitted in PHP

But when the form is submitted it does not retain the check boxes selected. For instance If I select and checked two check boxes how do i keep them checked even after the form is submitted? Thanks.

below is what i have.

<form method='post' action=''>
<?php
$SQLbrands="SELECT * FROM brands";
            $runBrands=mysqli_query($db, $SQLbrands) or die ("SQL Error");
            $noRow=mysqli_num_rows($runBrands);
            $brndTable = "<table border='1' cellspacing='0' cellpadding='1' id='brndTable1' class='brndTable1'>";
            $brndTable .= "<thead><tr><th class='brT11'>Brand Name</th><th class='brT21'>Variant</th><th class='brT31'>SKU</th><th class='brT41'></th></tr></thead>";
            $brndTable .= "<tbody>";
            while ($reK = mysqli_fetch_array($runBrands))
            {
                $wec = $reK['id']; $wec2 = $reK['bvariant']; $wec3 = $reK['bsku'];
                $brndTable .= "<tbody class='colormine'><tr>";
                $brndTable .= "<td class='brT1'>".$reK["bname"]."</td>";
                $brndTable .= "<td class='brT2'>".$reK["bvariant"]."</td>";
                $brndTable .= "<td class='brT3'>".$reK["bsku"]."</td>";
                $brndTable .= "<td class='brT4'><input type='checkbox' name='checkedMe[]' value='$wec' /></td>";
                $brndTable .= "</tr>";
            }
            $brndTable .= "</tbody>";
            $brndTable .= "</table>";


            echo $brndTable;
?>
<input type="submit" name="sendone" id="sendone" value="OneClick">
</form>

You need to store the settings of these checkbox values on your server (perhaps in your database). Then, next time your PHP script presents this form to your users, your PHP script should query this information, and write the checked attribute to check any checkboxes that should be checked.

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM