Welcome to Discuss Everything Forums...

If this is your first visit, be sure to check out the FAQ by clicking the link above. You may have to register before you can post: click the register link above to proceed.


 

Tags for this Thread

+ Reply to Thread
Results 1 to 2 of 2
  1. #1
    skinnypspplayer
    skinnypspplayer's Avatar
    Guest

    PHP form checkboxes to MySQL database?

    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

  2. #2
    Bernz
    Bernz's Avatar
    Guest
    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!

 

 

Quick Reply Quick Reply

Click here to log in


How many letters in the word Rabroad

Thread Information

Users Browsing this Thread

There are currently 1 users browsing this thread. (0 members and 1 guests)

Similar Threads

  1. Replies: 0
    Last Post: 12-23-2010, 04:15 PM
  2. Update MySQL database through PHP form?
    By selfrob in forum Discuss PHP
    Replies: 0
    Last Post: 04-08-2010, 03:01 PM
  3. Replies: 0
    Last Post: 11-14-2009, 02:17 PM
  4. Replies: 2
    Last Post: 09-02-2009, 02:16 AM
  5. Replies: 1
    Last Post: 04-29-2009, 04:52 PM

Bookmarks

Posting Permissions

  • You may post new threads
  • You may post replies
  • You may not post attachments
  • You may not edit your posts
  •