close ad
 
Important WebAssist Announcement
open ad
View Menu

Technical Support Forums

Free, outstanding support from WebAssist and your colleagues

rating

Checkbox group not writing to database

Thread began 12/02/2010 12:32 am by FrankJay | Last modified 12/07/2010 7:49 am by Jason Byrnes | 2355 views | 5 replies |

FrankJay

Checkbox group not writing to database

I have created a form using CSS form builder. It is made up of a few radio groups and a few checkbox groups. The information is written to a database when the form is submitted. All the radio group information is correctly written to the database. I am having a problem with the checkbox groups as the information is not stored to the database.
multiple_cb.php
Please help me with detailed fix.

Sign in to reply to this post

Jason ByrnesWebAssist

A checkbox group creates an array of the values that where selected.

The array needs to be converted to a comma separated list before is can be inserted to the database.

add the following code at line 1 of your page:

php:
<?php

if($_SERVER["REQUEST_METHOD"] == "POST")     {
    foreach(
$_POST as $key => $val) {
        if(
is_array($_POST[$key])) $_POST[$key] = implode(", "$_POST[$key]);     
    }
}
?>




this uses the implose function to convert the array to a comma separated list.

Sign in to reply to this post

FrankJay

Still not working

I have inserted the code as suggested. Still not writing to db.

Attached zip file of page in question showing additions. Kindly check page code for errors.

Much appreciated, Thanks Jason

Attached Files
multiple_cb.zip
Sign in to reply to this post

Jason ByrnesWebAssist

change line 43:

php:
$WA_fieldValuesStr = "".((isset($_POST["AgeGroup"]))?$_POST["AgeGroup"]:"")  ."" . "|" . "".((isset($_POST["GenderGroup"]))?$_POST["GenderGroup"]:"")  ."" . "|" . "".((isset($_POST["EthnicityGroup"]))?$_POST["EthnicityGroup"]:"")  ."" . "|" . "".((isset($_POST["CentreQuestionGroup[]"]))?$_POST["CentreQuestionGroup[]"]:"")  ."" . "|" . "".((isset($_POST["CentreComments"]))?$_POST["CentreComments"]:"")  ."" . "|" . "".((isset($_POST["AreaQuestionGroup[]"]))?$_POST["AreaQuestionGroup[]"]:"")  ."" . "|" . "".((isset($_POST["AreaComments"]))?$_POST["AreaComments"]:"")  ."" . "|" . "".((isset($_POST["Promotion[]"]))?$_POST["Promotion[]"]:"")  ."" . "|" . "".((isset($_POST["KeysComment"]))?$_POST["KeysComment"]:"")  ."" . "|" . "".((isset($_POST["GTAComment"]))?$_POST["GTAComment"]:"")  ."" . "|" . "".((isset($_POST["MeetComment"]))?$_POST["MeetComment"]:"")  ."";



to:

php:
$WA_fieldValuesStr = "".((isset($_POST["AgeGroup"]))?$_POST["AgeGroup"]:"")  ."" . "|" . "".((isset($_POST["GenderGroup"]))?$_POST["GenderGroup"]:"")  ."" . "|" . "".((isset($_POST["EthnicityGroup"]))?$_POST["EthnicityGroup"]:"")  ."" . "|" . "".((isset($_POST["CentreQuestionGroup"]))?$_POST["CentreQuestionGroup"]:"")  ."" . "|" . "".((isset($_POST["CentreComments"]))?$_POST["CentreComments"]:"")  ."" . "|" . "".((isset($_POST["AreaQuestionGroup"]))?$_POST["AreaQuestionGroup"]:"")  ."" . "|" . "".((isset($_POST["AreaComments"]))?$_POST["AreaComments"]:"")  ."" . "|" . "".((isset($_POST["Promotion"]))?$_POST["Promotion"]:"")  ."" . "|" . "".((isset($_POST["KeysComment"]))?$_POST["KeysComment"]:"")  ."" . "|" . "".((isset($_POST["GTAComment"]))?$_POST["GTAComment"]:"")  ."" . "|" . "".((isset($_POST["MeetComment"]))?$_POST["MeetComment"]:"")  ."";
Sign in to reply to this post

FrankJay

Now Working

Suggested code changes to line 43 has been implemented. Submitted checkbox group information is now successfully written and stored to db. Thanks for the help Jason.

Sign in to reply to this post

Jason ByrnesWebAssist

you're welcome.

Sign in to reply to this post

Build websites with a little help from your friends

Your friends over here at WebAssist! These Dreamweaver extensions will assist you in building unlimited, custom websites.

Build websites from already-built web applications

These out-of-the-box solutions provide you proven, tested applications that can be up and running now.  Build a store, a gallery, or a web-based email solution.

Want your website pre-built and hosted?

Close Windowclose

Rate your experience or provide feedback on this page

Account or customer service questions?
Please user our contact form.

Need technical support?
Please visit support to ask a question

Content

rating

Layout

rating

Ease of use

rating

security code refresh image

We do not respond to comments submitted from this page directly, but we do read and analyze any feedback and will use it to help make your experience better in the future.

Close Windowclose

We were unable to retrieve the attached file

Close Windowclose

Attach and remove files

add attachmentAdd attachment
Close Windowclose

Enter the URL you would like to link to in your post

Close Windowclose

This is how you use right click RTF editing

Enable right click RTF editing option allows you to add html markup into your tutorial such as images, bulleted lists, files and more...

-- click to close --

Uploading file...