Hello everyone!
I'm fairly new to PHP and was wondering if somone could help me solve a problem that I'm having when writing the value of a checkbox to a database. I have been working on this for days with no success. Thank you in advance for your help!
Jackie
Below is a portion of my html checkbox code:
<input type="checkbox" name="answer[0]" value="Coupons" />Coupons<br />
<input type="checkbox" name="answer[1]" value="Company Information" />Company Information<br />
<input type="checkbox" name="answer[2]" value="Editorials" />Editorials<br />
<input type="checkbox" name="answer[3]" value="Tips" />Tips and suggestions<br />
<input type="checkbox" name="answer[4]" value="Contests" />Contests<br />
<input type="checkbox" name="answer[5]" value="Other" />Other
Here is the PHP code that writes to the database and all I'm getting in the field is the word "Array" with no values:
$Q2_Array = $_POST['answer'];
for($a = 0; $a < sizeof($Q2_Total); $a++) {
$Q2_Total .= $Q2_Array[$a] . ",";
}
$sql = "INSERT SURVEYRESULTS (ANSWER1, ANSWER2, ANSWER3, ANSWER4, ANSWER5, ANSWER6, ANSWER7, ANSWER8, ANSWER9, ANSWER10) VALUES ('" . $answer1 . "', '" . $Q2_Array . "', '" . $answer3 . "', '" . $answer4 . "', '" . $answer5 . "', '" . $answer6 . "', '" . $answer7 . "', '" . $answer8 . "', '" . $answer9 . "', '" . $answer10 . "')";
$update = mysql_db_query ("emailsurvey", $sql) or die (mysql_error ($conn));