I am building a cms I want to iplement the ability to hide pages.
I have a row in mysql named hidden which stores the values 1 and 0. 1 will allow the page to be shown and 0 will hide it. The defalut value is set as 1.
When the box is checked I want the database to be updated with the value 0 and when it is unchecked I want it to be updated with the value 1.
I am looping out the current data stored into the database which provides the page title and two checkboxes one to delete the page and other to hide the page.
I use a foreach loop to update the values in the database but I can't figure out how to update it with a value when the checkbox is not checked.
if (isset($_POST['delete'])) {
foreach ($_POST['checkbox'] as $val){
mysql_query("DELETE FROM about WHERE id = ".$val."");
}
}
if(isset($_POST['visible'])){
foreach ($_POST['hidden'] as $hide){
mysql_query("UPDATE about SET hidden = 0 WHERE id = ".$hide."");
}
}
$sql = mysql_query("SELECT * FROM about ORDER BY id ASC");
while($row = mysql_fetch_assoc($sql)){
if($row['hidden'] ==) 0{
$checked = "checked=\"checked\"";
}else{
$checked = null;
}
echo "<p>Title:" . $row['title'] . "
<label for=\"checkbox".$i."\"> Hidden: </label><input name=\"hidden[]\" type=\"checkbox\" id=\"checkbox". $i . "\" value=\"". $row['id'] ."\" $checked>
<label for=\"checkbox".$ii."\"> Delete: </label><input name=\"checkbox[]\" type=\"checkbox\" id=\"checkbox". $ii . "\" value=\"". $row['id'] ."\"></p><hr>";
$i++;
$ii++;
}
echo"<input type=\"submit\" name=\"delete\" value=\"Delete\" class=\"submit\">";
echo"<input type=\"submit\" name=\"visible\" value=\"Hide\" class=\"submit\">";