Question
multiple checkbox values
Using PHP/MySQL and Dreamweaver 8
Problem:
Insert multiple checkbox values into a single database field using Dreamweaver Server Behaviors
I know that the checkboxes must be turned into an array.
My form has this:
(other fields omitted for brevity)
<input name="checkbox" type="checkbox" id="checkbox[0]" value="apples" />apples
<input name="checkbox" type="checkbox" id="checkbox[1]" value="oranges" />oranges
<input name="checkbox" type="checkbox" id="checkbox[2]" value="pears" />pear
Dreamweaver produces this code (before I added more than one checkbox in the form)
if ((isset($_POST["MM_insert"])) && ($_POST["MM_insert"] == "testform")) {
$insertSQL = sprintf("INSERT INTO test (text, radiogroup, checkbox, username) VALUES (%s, %s, %s, %s)",
GetSQLValueString($_POST['text'], "text"),
GetSQLValueString($_POST['RadioGroup'], "text"),
GetSQLValueString($_POST['checkbox'], "text"),
GetSQLValueString($_POST['hiddenField'], "text"));
mysql_select_db($database_db, $db);
$Result1 = mysql_query($insertSQL, $db) or die(mysql_error());
}
How do I change this code so that the "GetSQLValueString" posts the checkbox as an array and inserts it into one field deliminated with commas?
I'm just learning PHP and know enough to be dangerous! :) Thanks!
Problem:
Insert multiple checkbox values into a single database field using Dreamweaver Server Behaviors
I know that the checkboxes must be turned into an array.
My form has this:
(other fields omitted for brevity)
<input name="checkbox" type="checkbox" id="checkbox[0]" value="apples" />apples
<input name="checkbox" type="checkbox" id="checkbox[1]" value="oranges" />oranges
<input name="checkbox" type="checkbox" id="checkbox[2]" value="pears" />pear
Dreamweaver produces this code (before I added more than one checkbox in the form)
if ((isset($_POST["MM_insert"])) && ($_POST["MM_insert"] == "testform")) {
$insertSQL = sprintf("INSERT INTO test (text, radiogroup, checkbox, username) VALUES (%s, %s, %s, %s)",
GetSQLValueString($_POST['text'], "text"),
GetSQLValueString($_POST['RadioGroup'], "text"),
GetSQLValueString($_POST['checkbox'], "text"),
GetSQLValueString($_POST['hiddenField'], "text"));
mysql_select_db($database_db, $db);
$Result1 = mysql_query($insertSQL, $db) or die(mysql_error());
}
How do I change this code so that the "GetSQLValueString" posts the checkbox as an array and inserts it into one field deliminated with commas?
I'm just learning PHP and know enough to be dangerous! :) Thanks!
