I am getting a notice when I submit a form with empty checkboxes and I do not know how to get rid of them.
Here is my PHP:
if(count($_POST) > 0) {
$Q1 = $db->real_escape_string(trim($_POST['Q1']));
$Q2_1 = $db->real_escape_string(trim($_POST['Q2_1']));
$Q2_2 = $db->real_escape_string(trim($_POST['Q2_2']));
$Q2_3 = $db->real_escape_string(trim($_POST['Q2_3']));
$Q2_4 = $db->real_escape_string(trim($_POST['Q2_4']));
$Q2_5 = $db->real_escape_string(trim($_POST['Q2_5']));
$Q2_6 = $db->real_escape_string(trim($_POST['Q2_6']));
$Q3 = $db->real_escape_string(trim($_POST['Q3']));
if($insert = $db->query("
INSERT INTO response (Q1, Q2_1, Q2_2, Q2_3, Q2_4, Q2_5, Q2_6, Q3)
VALUES ('$Q1', '$Q2_1', '$Q2_2', '$Q2_3', '$Q2_4', '$Q2_5', '$Q2_6', '$Q3');
")) {
echo $db->affected_rows;
}
}
and here is my html:
<input type='checkbox' name="Q2_1" value="1">Not related to my issue<br/>
<input type='checkbox' name="Q2_2" value="1">Too complicated explanations<br/>
<input type='checkbox' name="Q2_3" value="1">Too much information<br/>
<input type='checkbox' name="Q2_4" value="1">Incorrect information<br/>
<input type='checkbox' name="Q2_5" value="1">Unclear information<br/>
<input type='checkbox' name="Q2_6" value="1">Incomplete information<br/>
EDIT The error message is: Notice: Undefined index: Q2_1 in C:\xampp\htdocs\srsurvey\connect.php on line 49
Notice: Undefined index: Q2_4 in C:\xampp\htdocs\srsurvey\connect.php on line 52
Notice: Undefined index: Q2_5 in C:\xampp\htdocs\srsurvey\connect.php on line 53
Notice: Undefined index: Q2_6 in C:\xampp\htdocs\srsurvey\connect.php on line 54
when the checkboxes are left empty