I am trying to get the value from the checkbox selected in a form inserted into a database using php and sql. I have included the html and some php I am trying to get to work. The first bit of php works great. The second bit of php is one of many attempts to get the value of the checkbox from the form inserted into a database. Thank you for your help!
<?php
$sql = "INSERT into students set student_number = '{$_POST['student_number']}',
first_name = '{$_POST['first_name']}', last_name = '{$_POST['last_name']}', degree =
'{$_POST['degree']}'";
mysql_query($sql);
?>
<?php
$classes->bind_result($class);
$classes->execute();
$class = array();
while ($classes->fetch()) {
$class[] = $class;
}
?>
<div class="div1">COP1000:</div><input class="checkbox1" type="checkbox"
value="COP1000" name="class[]" id="class[]" /><br />
<div class="div1">COP2800:</div><input class="checkbox1" type="checkbox"
value="COP2800" name="class[]" id="class[]" /><br />
<div class="div1">CIS2910C:</div><input class="checkbox1" type="checkbox"
value="CIS2910C" name="class[]" id="class[]" /><br />
<div class="div1"> COP2830:</div><input class="checkbox1" type="checkbox"
value="COP2830" name="class[]" id="class[]" /><br /><br />
sprintfto build you query and usemysql_real_escapestring.. you don't want SQL injection attacks :$class[] = $class;doesn't make sense - you're building an array of empty arrays.