-
Notifications
You must be signed in to change notification settings - Fork 0
/
finalChanges.php
132 lines (123 loc) · 3.87 KB
/
finalChanges.php
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
$name=$rollno=$dept=$email=$address=$aboutme="";
$Ename=$Edept=$Eemail=$Eaddress="";
$pwd="";
$error=TRUE;
$servername="localhost";
$username="joy";
$password="password";
$dbname="mydb";
$conn=new mysqli($servername,$username,$password,$dbname);
if($conn->connect_error)
{
die("Connection Failed: ".$conn->connect_error);
}
else
echo "Connected!<br>";
$stmt=$conn->prepare("UPDATE student
SET Name=?,Department=?,Email=?,Address=?,Aboutme=?
WHERE Rollno=?;");
$stmt->bind_param("ssssss",$name,$dept,$email,$address,$aboutme,$rollno);
if($_SERVER["REQUEST_METHOD"]=="POST")
{
if(empty($_POST["name"]))
{
$Ename="Name can't be empty";
$error=TRUE;
}
else
{
$name=validate($_POST["name"]);
if(!preg_match("/^[a-zA-Z ]*$/",$name))
{
$Ename="Only alphabets and spaces allowed in name";
$error=TRUE;
}
else
{
$error=FALSE;
}
}
$dept=$_POST["department"];
if(empty($_POST["email"]))
{
$Eemail="Email can't be empty";
$error=TRUE;
}
else
{
$email=validate($_POST["email"]);
if(!filter_var($email,FILTER_VALIDATE_EMAIL))
{
$Eemail="Improper email format";
$error=TRUE;
}
else
{
$error=FALSE;
}
}
if(empty($_POST["address"]))
{
$Eaddress="Address can't be empty";
$error=TRUE;
}
else
{
$address=htmlspecialchars($_POST["address"]);
$error=FALSE;
}
$aboutme=htmlspecialchars($_POST["aboutme"]);
$rollno=$_POST["rollno1"];
}
if(!$error)
{
if($stmt->execute())
{
echo "<br>Successfully Edited!!";
}
else
{
print_r(mysqli_error_list($conn));
}
}
else
{
echo "Invalid Data";
}
function validate($data)
{
$data=trim($data);
$data=stripslashes($data);
$data=htmlspecialchars($data);
return $data;
}
?>
<!DOCTYPE html>
<html lang="en">
<head>
<style>
body{
font-family: "Comic Sans MS";
}
button{
background-color: lightgrey;
border: 1px solid grey;
border-radius: 5px;
padding: 5px;
outline: none;
font-size: 20px;
box-shadow:1px 1px 0 grey;
cursor: pointer;
}
button:active{
box-shadow:0px 0px 0 grey;
transform: translateY(1px);
transform:translateX(1px);
}
</style>
</head>
<body>
<br><br><a href="index.php"><button>RETURN</button></a>
</body>
</html>