Posted By

davidsword on 09/26/08


Tagged

form database checkbox


Versions (?)

Who likes this?

3 people have marked this snippet as a favorite

Nix
oriolfb
hasssan


Inserting/Retrieving checkbox values from database


 / Published in: PHP
 

URL: http://davidsword.ca/

I always forget how to do this...

  1. //On form; checkbox option
  2. echo "<input name='chbx' value='1' type='checkbox' CHECKED>";
  3.  
  4.  
  5. //After form, find value of chbx for database
  6. $showhide = (isset($_POST['chbx']) && $_POST['chbx'] == '1')? 1 : 0;
  7.  
  8.  
  9. //Retrieving from database, find if chbx is checked for redisplaying original sumbission
  10. $ckd = (isset($row['chbx']) && $row['chbx'] == '1')? "CHECKED" : "";
  11. $checkbox = "<input name='chbx' value='1' type='checkbox' $chk>";

Report this snippet  

Comments

RSS Icon Subscribe to comments
Posted By: Nix on September 26, 2008

Cool, thanks ;)

You need to login to post a comment.