Inserting/Retrieving checkbox values from database


/ Published in: PHP
Save to your folder(s)

I always forget how to do this...


Copy this code and paste it in your HTML
  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>";

URL: http://davidsword.ca/

Report this snippet


Comments

RSS Icon Subscribe to comments

You need to login to post a comment.