PHP form checkboxes to MySQL database?

  • Thread starter Thread starter skinnypspplayer
  • Start date Start date
S

skinnypspplayer

Guest
I'm having a bit of trouble inserting data into a MySQL database. I have a form with normal HTML form checkboxes where users can select a few 'items'. When I try to submit the form, only one item (if mulitple are selected) shows up in the database. Everything else works fine (text input, radio buttons, etc.) but I'm having trouble with this. Any help?

If you need more info then just ask
 
Checkboxes have a special behavior in HTML forms (this has nothing to do with PHP). Here's the catch:

- When you click a checkbox and submit a form, you'll get: $_GET['mycheckbox']='value' or $_POST['mycheckbox']='value'.

- When you DON'T check a checkbox, you get... NOTHING!

That's the catch. An unchecked checkbox is completely invisible in your $_GET or $_POST variable.

If you want to use checkboxes, you have to do something like this:

if (empty($_GET['mycheckbox']='value'))
$checkbox1 = 'NULL';
else
$checkbox1 = $_GET['mycheckbox'];

Hope this helps! Good luck!
 
Back
Top