i've been searching related questions for answers but it seems like my case is unique. Am attempting use values passed in a link in an update statement. Am able to populate my update form using the values passed in the link, but the update fails even though i have all variable set.
This is the link returning the value
<a href="edit_student.php?student=<?php echo urldecode($student["student_id"]) ?>"><span class="glyphicon glyphicon-pencil"></span></a>
This is my function
function find_student_by_id($student_id) {
global $connection;
$query = "select * from students where student_id = {$student_id} limit 1";
$found_student = mysqli_query($connection, $query);
confirm_query($found_student);
return $found_student;
}
This is my update code
<?php
// Checking for a set employee ID
if (isset($_GET["student"])) {
$selected_student = find_student_by_id($_GET["student"]);
}
// Processing the form
if (isset($_POST['submit'])) {
# process the form
$student_id = $_GET["student"];
$fname = ucfirst($_POST["s_fname"]);
$lname = ucfirst($_POST["s_lname"]);
$mname = ucfirst($_POST["s_mname"]);
$sex = $_POST["sex"];
$dob = $_POST["s_dob"];
$home_address = ucwords($_POST["home_address"]);
$guardian = ucwords($_POST["guardian"]);
$contact_address = ucwords($_POST["contact_address"]);
$phone = $_POST["g_phone"];
$email = $_POST["g_email"];
$year = $_POST["entry_year"];
$query = "update students set s_fname = '{$fname}', s_lname = '{$lname}', s_mname = '{$mname}', sex = '{$sex}', s_dob = {$dob}, home_address = '{$home_address}', guardian = '{$guardian}', contact_address = '{$contact_address}', g_phone = {$phone}, g_email = '{$email}', entry_year = {$year}) where student_id = {$student_id}";
$result = mysqli_query($connection, $query);
if ($result) {
# successful
$_SESSION["message"] = "Updated student information successfully.";
if ($year == 0) {
redirect_to("preschool.php");
} elseif ($year == 1) {
redirect_to("year1.php");
} elseif ($year == 2) {
redirect_to("year2.php");
} elseif ($year == 3) {
redirect_to("year3.php");
} elseif ($year == 4) {
redirect_to("year4.php");
} elseif ($year == 5) {
redirect_to("year5.php");
} elseif ($year == 6) {
redirect_to("year6.php");
}
} else {
# failure
$_SESSION["message"] = "Update unsuccessful.";
redirect_to("edit_student.php");
}
}
?>
When i submit the form, i get the error in the image attached
I have selected_student set at the top of my code, yet i still get undefined variable warning. How do i fix this, i have been on it for some hours now. Appreciate any help