-
Notifications
You must be signed in to change notification settings - Fork 3
/
Copy pathedit.php
181 lines (164 loc) · 3.89 KB
/
edit.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
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
<?php
session_start();
$userName=$_SESSION['userName'];
$name=$_SESSION['name'];
if(!isset($_SESSION['userName']))
{
header("Location:login.php");
}
?>
<html>
<head>
<style>
* {
box-sizing: border-box;
}
body {
font-family: Arial, Helvetica, sans-serif;
}
/* Style the header */
.header {
grid-area: header;
background-color: #E98C53;
padding: 30px;
text-align: center;
font-size: 35px;
}
/* The grid container */
.grid-container {
display: grid;
grid-template-areas:
'header header header header header header'
'left middle middle middle middle middle'
'footer footer footer footer footer footer';
/* grid-column-gap: 10px; - if you want gap between the columns */
}
.left,
.middle,
.right {
padding: 10px;
height: 300px; /* Should be removed. Only for demonstration */
}
/* Style the left column */
.left {
grid-area: left;
}
/* Style the middle column */
.middle {
grid-area: middle;
}
/* Style the right column */
.right {
grid-area: right;
}
/* Style the footer */
.footer {
grid-area: footer;
background-color: #85C1E9;
padding: 10px;
text-align: center;
}
</style>
</head>
<body>
<div class="grid-container">
<div class="header">
<h2 style="color: #2E4053"; align="left">XCompany <?php
$name=$_SESSION['name'];
?></h2>
</div>
<div class="left" style="background-color:#aaa;">
<ul>
<li><a href="nhome.php">Dashboard</a></li>
<li><a href="view.php?userName=<?php echo $userName; ?>">View Profile</a></li>
<li><a href="edit.php">Edit Profile</a></li>
<li><a href="changepic.php">Change Profile Picture</a></li>
<li><a href="changepass.php">Change Password</a></li>
<li><a href="logout.php">Logout</a></li>
</ul>
</div>
<div class="middle" style="background-color:#bbb;">
<?php
$con=mysqli_connect("localhost","root","","testdb");
if(!$con)
{
die("Connection Error: ".mysqli_connect_error()."<br/>");
}
$sql="SELECT * FROM customers WHERE userName='$userName'";
$result=mysqli_query($con,$sql);
if(mysqli_num_rows($result)>0)
{
($row=mysqli_fetch_array($result));
{
$name=$row["name"];
$email=$row["email"];
$gender=$row["gender"];
$dob=$row["dob"];
}
}
else
{
echo "No data found.<br/>";
}
?>
<fieldset align="center">
<legend>Edit Profile</legend>
<form action="<?php htmlspecialchars($_SERVER['PHP_SELF']); ?>" method="POST">
<table align="left">
<tr>
<td>Name</td>
<td><input type="text" name="name" value=<?php echo"$name" ?>></td>
</tr>
<tr>
<td>Email</td>
<td><input type="text" name="email" value=<?php echo"$email" ?>></td>
</tr>
<tr>
<td>Gender</td>
<td><input type="text" name="gender" value=<?php echo"$gender" ?>></td>
</tr>
<tr>
<td>Date of Birth</td>
<td><input type="text" name="dob" value=<?php echo"$dob" ?>></td>
</tr>
<tr>
<td></td>
<td><input type="submit" name="change" value="Submit"/></td>
</tr>
</table>
</form>
</fieldset>
</div>
<?php
if (isset($_POST['change']))
{
$con=mysqli_connect("localhost","root","","testdb");
if(!$con)
{
die("Connection Error: ".mysqli_connect_error()."<br/>");
}
if (isset($userName))
{
$name=$_POST['name'];
$email=$_POST['email'];
$gender=$_POST['gender'];
$dob=$_POST['dob'];
$sql="UPDATE customers SET name='$name',email='$email',gender='$gender',dob='$dob' WHERE userName='$userName'";
if(mysqli_query($con,$sql))
{
header("Location:view.php");
}
else
{
echo "Error in updating: ".mysqli_error($con);
}
mysqli_close($con);
}
}
?>
<div class="footer">
<p>Copyright © 2020</p>
</div>
</div>
</body>
</html>