-
Notifications
You must be signed in to change notification settings - Fork 2
Expand file tree
/
Copy pathedit_student_to_db.php
More file actions
111 lines (94 loc) · 3.52 KB
/
edit_student_to_db.php
File metadata and controls
111 lines (94 loc) · 3.52 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
<?php
session_start();
if(!isset($_SESSION['logged_in__admin_name'])){
echo '<script type="text/javascript"> location.href = "admin_login.php" </script>';
}
else{
$host = "localhost";
$username = "root";
$password = "";
$dbname = "hac";
$conn = new mysqli($host, $username, $password, $dbname);
$roll = $_POST['RollNo'];
$name = $_POST['name'];
$no_of_courses = $_POST['No_of_courses'];
$list_of_c = '';
$len = 0; //Length of courses
if(!empty($_POST['course'])) {
foreach($_POST['course'] as $value){
$len+=1;
$list_of_c .= "$value," ;
}
}
$age = $_POST['Age'];
$gender = $_POST['gender'];
$blood_grp = $_POST['blood_group'];
$branch = $_POST['Branch'];
$passing_year = $_POST['Passing_Year'];
$program = $_POST['Program'];
$ph_no = $_POST['Phone'];
$DOB = $_POST['DOB'];
$list_of_courses = substr($list_of_c, 0, -1);
//Validity Checks for each input
// No. of courses
if($len != $no_of_courses)
{
echo "<script type='text/javascript'>alert('Enter correct number of courses according to selected List of Courses!'); </script>";
echo '<script type="text/javascript"> location.href = "edit_home.php" </script>';
exit();
}
// Age
$today = date("Y-m-d");
$diff = date_diff(date_create($DOB), date_create($today));
$age_actual = $diff->format('%y');
if($age_actual != $age)
{
echo "<script type='text/javascript'>alert('Enter correct age according to DOB!'); </script>";
echo '<script type="text/javascript"> location.href = "edit_home.php" </script>';
exit();
}
// Blood Group
$available_bgs = array("A+", "A-", "B+", "B-","AB+", "AB-", "O+", "O-");
if (!in_array($blood_grp, $available_bgs)) {
echo "<script type='text/javascript'>alert('Enter blood group in correct format'); </script>";
echo '<script type="text/javascript"> location.href = "edit_home.php" </script>';
exit();
}
// Passing Year
$year = date("Y");
if ($passing_year > $year + 5 || $passing_year < $year - 5) {
echo "<script type='text/javascript'>alert('Please fill corect passing out year !'); </script>";
echo '<script type="text/javascript"> location.href = "edit_home.php" </script>';
exit();
}
// Phone Number
$filtered_phone_number = filter_var($ph_no, FILTER_SANITIZE_NUMBER_INT);
$phone_to_check = str_replace("-", "", $filtered_phone_number);
if (strlen($phone_to_check) < 10 || strlen($phone_to_check) > 14) {
echo "<script type='text/javascript'>alert('Enter correct format of phone number ex. +91 XXXXXXXXXX'); </script>";
echo '<script type="text/javascript"> location.href = "edit_home.php" </script>';
exit();
}
$sql = "UPDATE student SET name='$name', noOfCourses=$no_of_courses,
listOfCourses='$list_of_courses', age=$age, gender='$gender', bloodGroup='$blood_grp', branch='$branch',
passingYear=$passing_year, programme='$program', phone='$ph_no', dob='$DOB' WHERE
rollNo=$roll";
if ($conn->query($sql) === TRUE) {
echo "<script type='text/javascript'>alert('Updated Record Successfully !'); </script>";
echo '<script type="text/javascript"> location.href = "admin.php" </script>';
}
else {
//echo "Error: " . $sql . "<br>" . $conn->error;
}
}
?>
<?php include("sidebar_admin.php"); ?>
<!DOCTYPE html>
<html>
<head>
<link rel="stylesheet" href="css/bootstrap.min.css">
<link href="https://cdn.jsdelivr.net/npm/bootstrap@5.0.2/dist/css/bootstrap.min.css" rel="stylesheet">
<link href="https://cdn.jsdelivr.net/npm/bootstrap-icons@1.5.0/font/bootstrap-icons.css" rel="stylesheet">
<script src="https://cdn.jsdelivr.net/npm/bootstrap@5.0.2/dist/js/bootstrap.bundle.min.js"></script>
</head>
</html>