I have a drop down menu populated by a MYSQL table. Which I have included the id and the name of a Faculty. I want to post the selected item's id on drop down menu to the next page. Which is addstudent.php. The PHP code is as follows.
<form action="addstudent.php" method="post">
<div class="input-group">
<?php
echo '<select class="form-control" id="sel1">';
while ($row = mysqli_fetch_array($result)) {
echo '<option value = "'.$row['faculty_id'].'">' . $row['name'] . '</option>';
}
echo '</select>';
?>
<span class="input-group-btn ml-2">
<button class="btn btn-primary" type="submit">Add Student</button>
</span>
</div>
</form>
The code on Undefined index is on addstudent.php page. The code is as below
if (isset($_POST['faculty_id'])) {
$faculty_id = $_POST['faculty_id'];
} else{
echo "Something is wrong";
}