[英]Retaining check box values after the form is submitted in PHP
但是,提交表单后,它不会保留选中的复选框。 例如,如果我选中并选中了两个复选框,即使提交了表单后,如何保持选中状态? 谢谢。
以下是我所拥有的。
<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>
您需要将这些复选框值的设置存储在服务器上(也许在数据库中)。 然后,下一次您的PHP脚本向用户显示此表单时,您的PHP脚本应查询此信息,并编写checked
属性以选中应选中的所有复选框。
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.