View Full Version : New to Dreamweaver cs4 and MySQL, need advice/help

04-24-2009, 08:57 AM
Hi all,
I am trying to develop an online practice page for a multiple choice test.
I have created a MySQL database table for the questions with.
1. Question number (primary Key)
2. Category (Text)
3. Question (Text)
4. Image
5. possible answer a through to f (6 seperate columns)
6. correct answer. This could be one or more of the possible answers a to f. So I have made it a set('a','b','c','d','e','f')
7. answer text.

The problem I am having is with column 6, the correct answer.
I have built a php page to insert new questions, created a form to input the data using a checkbox group for the correct answer, added an insert record server behaviour to the form.
Everything works apart from the correct answer which only inserts one item, even if several checkboxes are checked.
I have tried various values in the "submit as" dialogue box for the server behaviour but non seem to match a set in MySQL.
My questions are.
Am I going about this the right way?
Is a set the best way to store this data in MySQL?
Is there a way to get the insert record server behaviour to pick up all the items checked in a checkbox group?
Apologies if I'm asking a simple question here but I am new to both MySQL and Dreamweaver and it's doing my head in now :confused:
Many thanks in advance for any help and ideas.


04-24-2009, 09:15 AM
you are using the dreamweaver code to do this from their wizard?

04-24-2009, 09:30 AM
you are using the dreamweaver code to do this from their wizard?

I tried using the wizard and it didn't work so I tried designing my own form and applying the server behaviour to it. This gave much the same results.
It would appear that the server behaviour only allows single checkboxes with a 1 or 0, yes or no type of answer.
I have just noticed that when I edit the server behavour the value drop down list in the insert record dialogue window shows a value for each checkbox. I am only picking up one and can't see a way to pick up the others??

04-24-2009, 10:13 AM
you need to learn the wonders of PHP

your project will push the envelope of DW code so yo achieve what your after you will need to learn the language

04-24-2009, 04:05 PM
Just realised. All I needed to do was implode the array before the server behaviour got hold of it.
Added the following code as the first action in the server behaviour code..

if (isset($_POST['correct_answer'])) {
$_POST['correct_answer'] = implode(',', $_POST['correct_answer']);
} else {
$_POST['correct_answer'] = 'none';

I inserted it just before the $insertSQL = sprintf line of code generated by dreamweaver.

I will need to tidy up the error handling in the else statement as 'none' is invalid as well in my application but it works so far.
Of course the server behaviour is no longer editable in dreamweaver but hey ho.
I find it quite fascinating that you can get dreamweaver to do the bulk of you code for you and just add/amend it to suit. Saves a lot of hard coding :wink:
Hope this is usefull.