-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathaccount.php
168 lines (151 loc) · 4.49 KB
/
account.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
<?php
include('dbconnection.php');
session_start();
$qr = "SELECT id FROM users WHERE email = '".$_SESSION['email']."'";
$run_qr = mysqli_query($connection, $qr);
$row = mysqli_fetch_assoc($run_qr);
$id = $row['id'];
?>
<!DOCTYPE html>
<html>
<head>
<title>Account</title>
<meta name="viewport" content="width=device-width, initial-scale=1">
<style>
* {
box-sizing: border-box;
}
body { width: 900px; margin: auto; }
input[type=text], input[type=email], input[type=number], select, textarea {
width: 100%;
padding: 12px;
border: 1px solid #ccc;
border-radius: 4px;
resize: vertical;
}
label {
padding: 12px 12px 12px 0;
display: inline-block;
}
input[type=submit] {
background-color: #4CAF50;
color: white;
padding: 12px 20px;
border: none;
border-radius: 4px;
cursor: pointer;
float: right;
}
input[type=submit]:hover {
background-color: #45a049;
}
.container {
border-radius: 5px;
background-color: #f2f2f2;
padding: 20px;
}
.col-25 {
float: left;
width: 25%;
margin-top: 6px;
}
.col-75 {
float: left;
width: 75%;
margin-top: 6px;
}
/* Clear floats after the columns */
.row:after {
content: "";
display: table;
clear: both;
}
/* Responsive layout - when the screen is less than 600px wide, make the two columns stack on top of each other instead of next to each other */
@media screen and (max-width: 600px) {
.col-25, .col-75, input[type=submit] {
width: 100%;
margin-top: 0;
}
}
</style>
</head>
<body>
<h2>Account Details</h2>
<p>Please update the details if you want to change.</p>
<div class="container">
<form action="<?php echo htmlspecialchars($_SERVER["PHP_SELF"]); ?>" method="POST">
<?php
$query = "SELECT * FROM users WHERE id = ".$id;
$run_query = mysqli_query($connection, $query);
while( $result = mysqli_fetch_assoc($run_query) )
{
if($result){ ?>
<div class="row">
<div class="col-25">
<label for="name">Name</label>
</div>
<div class="col-75">
<input type="text" id="name" name="name" placeholder="Name" value="<?php echo $result['full_name']; ?>">
</div>
</div>
<div class="row">
<div class="col-25">
<label for="email">Email</label>
</div>
<div class="col-75">
<input type="email" id="email" name="email" placeholder="Email Address" value="<?php echo $result['email']; ?>">
</div>
</div>
<div class="row">
<div class="col-25">
<label for="name">Password</label>
</div>
<div class="col-75">
<input type="text" id="name" name="password" placeholder="Password" value="<?php echo $result['password']; ?>">
</div>
</div>
<div class="row">
<div class="col-25">
<label for="phone">Phone No</label>
</div>
<div class="col-75">
<input type=number id="phone" name="phone" placeholder="Phone Number" value="<?php echo $result['phone']; ?>">
</div>
</div>
<div class="row">
<div class="col-25">
<label for="name">Address</label>
</div>
<div class="col-75">
<input type="text" id="name" name="address" placeholder="Address" value="<?php echo $result['address']; ?>">
</div>
</div>
<?php } } ?>
<div class="row"><br><br>
<input type="submit" value="Save Changes">
</div>
</form>
</div>
</body>
</html>
<?php
$email = $password = $name = $phone = $address = "";
if($_SERVER["REQUEST_METHOD"] == "POST")
{
$email = test_input($_POST["email"]);
$name = test_input($_POST["name"]);
$password = test_input($_POST["password"]);
$phone = test_input($_POST["phone"]);
$address = test_input($_POST["address"]);
$qry = "UPDATE users SET email='".$email."', full_name='".$name."', password=".$password.", phone=".$phone.", address='".$address."' WHERE id=".$id;
$run_qry = mysqli_query($connection, $qry);
}
function test_input($data)
{
$data = trim($data);
$data = stripslashes($data);
$data = htmlspecialchars($data);
return $data;
}
mysqli_close($connection);
?>