-
Notifications
You must be signed in to change notification settings - Fork 2
Expand file tree
/
Copy pathstudent_add_info_to_db.php
More file actions
132 lines (109 loc) · 4.06 KB
/
student_add_info_to_db.php
File metadata and controls
132 lines (109 loc) · 4.06 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
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
<?php
session_start();
if(!isset($_SESSION['logged_in__stu_roll'] )){
echo '<script type="text/javascript"> location.href = "student_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);
if(isset($_FILES['image'])){
$errors= array();
$file_name = $_FILES['image']['name'];
$file_size =$_FILES['image']['size'];
$file_tmp =$_FILES['image']['tmp_name'];
$file_type=$_FILES['image']['type'];
$file_ext=strtolower(end(explode('.',$_FILES['image']['name'])));
$extensions= array("jpeg","jpg","png");
if(in_array($file_ext,$extensions)=== false){
$errors[]="extension not allowed, please choose a JPEG or PNG file.";
}
if($file_size > 2097152){
$errors[]='File size must be excately 2 MB';
}
$file_name = $roll.".jpg";
if(empty($errors)==true){
move_uploaded_file($file_tmp,"images_student/".$file_name);
echo "Success";
}else{
print_r($errors);
}
}
//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 = "student_add_own_details.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 = "student_add_own_details.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 = "student_add_own_details.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 = "student_add_own_details.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 = "student.php" </script>';
}
else {
//echo "Error: " . $sql . "<br>" . $conn->error;
}
}
?>
<?php include("sidebar_student.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>