-
Notifications
You must be signed in to change notification settings - Fork 2
Expand file tree
/
Copy pathadmin_edit_faculty_to_db.php
More file actions
93 lines (79 loc) · 2.82 KB
/
admin_edit_faculty_to_db.php
File metadata and controls
93 lines (79 loc) · 2.82 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
<?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'];
// $list_of_c = $_POST['course'];
// $each = explode(",", $list_of_c);
// $length = count($each);
// if ($length == 1)
// {
// $list_of_courses = $each[0];
// }
// else
// {
// $list_of_courses = substr($list_of_c, 0, -1);
// }
$age = $_POST['Age'];
$gender = $_POST['gender'];
$blood_grp = $_POST['blood_group'];
$dept = $_POST['Dept'];
$jd = $_POST['JD'];
$ph_no = $_POST['Phone'];
$DOB = $_POST['DOB'];
//Validity Checks for each input
// 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 = "admin_edit_faculty_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 = "admin_edit_faculty_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 = "admin_edit_faculty_home.php" </script>';
exit();
}
$sql = "UPDATE faculty SET name='$name', age=$age, gender='$gender', bloodGroup='$blood_grp',
department='$dept', join_date='$jd', phone='$ph_no', dob='$DOB' WHERE
id=$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>