I have created a DB which consists of courses. Students logged in can choose the courses using a dynamic checkbox and submitting it via a form.
<form method="POST" action="checkbox.php">
<?php
$sql1 = "SELECT course_id FROM course WHERE sem ='" .$_POST['sem']."'";
$result = mysqli_query($conn,$sql1);
while($row = mysqli_fetch_array($result)) {
echo "<input type='checkbox' name='course_id[]' value='{$row['course_id']}'>" . $row['course_id'];
}
?>
<br>
<button ><span>Submit</span></button>
</form>
The form calls the PHP which consists of an array to echo the values. But I am getting an error from the php which says "undefined index 12IS36"..Here 12IS36 is the course stored in the DB.
PHP Code
<?php
//connection
foreach($_POST['course_id'] as $course) {
echo $_POST[$course];
}
?>