checkbox help!

I have a mysql table with a field named ‘status’-tinyint(1).

I have a form that show all of the images from that table with 2 checkboxes for each image. One for ‘hide’ and one for ‘show’. This is just a form for me to be able to hide pictures in the gallery of a website.

When ‘status’ is set to 0 the image is hidden from the gallery, when status is set to 1 it is shown in the gallery. I have written code for this but there is a problem somewhere as it never changes the value in ‘status’

[php]<?php
include ‘connect.php’;

if(isset($_POST[‘zero’])){

  $chk = (array) $_POST['zero'];
  $p = implode(',',array_keys($chk)); 

  if ($sql = mysql_query("UPDATE reptile_thumbs SET status = 0 WHERE `id` = $p")){
     echo 'Image hidden from gallery.';
	 echo $p;
  }
  else{
  echo 'There has been a problem. Go back and try again.';
  }
}

else if(isset($_POST['one'])){
  
  $chk = (array) $_POST['one'];
  $p = implode(',',array_keys($chk)); 

  if ($sql = mysql_query("UPDATE reptile_thumbs SET status = 1 WHERE `id` = $p")){
     echo 'Image visible in gallery.';

}
else{
echo ‘There has been a problem. Go back and try again.’;
}
}

?>[/php]
Can anyone see what is going wrong?

Thanks for looking…

I think yyou need radio instaead of checkbox

for the radio buttons have them have a name like

<input type='radio' name='chkname' value='1'>Show
<input type='radio' name='chkname' value='0'>Hide

[php]
$radio = $_POST[‘chkname’];
[/php]

now just insert $radio, it will contain either 0 or 1

to display the selected radio from database

[php]

<?php $selected_radio = $_POST['status']; $row = mysql_fetch_assoc($result); ?>

<input type=“radio” name=“chkname” value=“1” <?php if ($row['status'] == "1"){echo "checked";} ;?>/>Show
<input type=“radio” name=“chkname” value=“0” <?php if ($row['status'] == "0"){echo "checked";} ;?>/>Hide
[/php]

Sponsor our Newsletter | Privacy Policy | Terms of Service