-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathuser.php
More file actions
executable file
·241 lines (211 loc) · 8.51 KB
/
Copy pathuser.php
File metadata and controls
executable file
·241 lines (211 loc) · 8.51 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
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
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
<?php
session_start(); // Start the session
// Database connection
include('dbconnection.php');
// Handle logout
if (isset($_GET['logout'])) {
session_destroy();
header("Location: index.php");
exit();
}
?>
<?php
include('dbconnection.php');
$ffname = $llname = $eemail = $mmobile=$ppassword = ""; // Initialize variables (yo chai rakhnai parxa yo bhayana bhanne hamro refresh bhaya paxi input field ko value ma j pai tei garbage value aauxa tesialey
// i.e variables $ffname, $llname, etc., are not defined when the form is reloaded after the POST request is processed. This happens because those variables are only set during the GET request when the user data is fetched from the database.)
if ($_SERVER["REQUEST_METHOD"] == "GET") {
$uid = $_GET['uid']; // Get the uid from the URL
$success=false;
// Fetch the specific user by uid
$sql = "SELECT * FROM users WHERE uid = $uid";
$result = mysqli_query($conn, $sql);
if ($row = mysqli_fetch_assoc($result)) {
$ffname = $row['fname'];
$llname = $row['lname'];
$eemail = $row['email'];
$mmobile = $row['mobile'];
$pass=$row['password'];
} else {
echo "User not found";
}
} else if ($_SERVER["REQUEST_METHOD"] == "POST") {
$uid = $_POST['uid']; // Get the uid from the hidden input field
if (isset($_POST['profiles'])) {
$uname = $_POST['uname'];
$fname = $_POST['fname'];
$lname = $_POST['lname'];
$email = $_POST['email'];
$resphone = $_POST['resphone'];
$phone = $_POST['phone'];
// Update the user information
$sql = "UPDATE users SET fname='$fname', lname='$lname', email='$email', mobile='$phone' WHERE uid=$uid";
$result = mysqli_query($conn, $sql);
if (!$result) {
echo "Failed to update user.";
} else {
// Fetch the updated data from the database again after update
$sql = "SELECT * FROM users WHERE uid = $uid";
$result = mysqli_query($conn, $sql);
if($result){
$success=true;
}
if ($row = mysqli_fetch_assoc($result)) {
$ffname = $row['fname'];
$llname = $row['lname'];
$eemail = $row['email'];
$mmobile = $row['mobile'];
}
}
}
}
?>
<!DOCTYPE html>
<html lang="en">
<head>
<meta charset="UTF-8">
<meta name="viewport" content="width=device-width, initial-scale=1.0">
<title>Document</title>
</head>
<link rel="stylesheet" href="styles.css">
<link rel="stylesheet" href="user.css">
<link
rel="stylesheet"
href="https://cdnjs.cloudflare.com/ajax/libs/font-awesome/6.0.0/css/all.min.css"
/>
<body class="body">
<section id="header">
<nav>
<div class="logo">
<img src="Images/logo12.png" alt="" />
</div>
<ul>
<li class="active"><a href="index.php">Home</a></li>
<li>My Tickets</li>
<li><a href="booking.php">Booking</a></li>
<li><a href="movie.php">Movie</a></li>
<li><a href="ticket.php">Ticket Rate</a></li>
</ul>
<div class="after">
<ion-icon name="person-circle-outline" class="icon"></ion-icon>
<?php echo '<a href="user.php"> <h2 class="session-user" style="margin-top:20px;">' . htmlspecialchars($_SESSION["email"]) . '</h2></a>'; ?>
<div>
<div class="logout">
<button><a href="?logout=true">Logout</a></button>
</div>
</nav>';
</section>
<?php
if($success){
echo' <div class="form-popup" id="myForm">
<form class="form-container">
<h2>Profile Update</h2>
<p>Sucessful</p>
<p class="btn cancel" onclick="closeForm()">
<span class="close"><i class="fas fa-check"></i> Close</span>
</p>
</form>
</div>';
}
?>
<section id="container-body">
<div class="tab-titles11">
<p class="tab-links " onclick="opentab('password')">Change Password</p>
<p class="tab-links active-link" onclick="opentab('profile')">Edit Profile</p>
</div>
<div class="tab-contents " id="password">
<form action="" class="password" method="post">
<div class="curr">
<p class="ptext">Current Password</p>
<input type="password" name="currpassword" value="<?php echo $pass; ?>">
</div>
<div class="newp">
<p class="ptext">New Password</p>
<input type="password" name="newpassword">
</div>
<div class="newcp">
<p class="ptext">Confirm Password</p>
<input type="password" name="newcpassword">
</div>
<button>Save</button>
</form>
</div>
<div class="tab-contents active-tab" id="profile">
<form action="user.php" method="post" class="user" >
<div class="username">
<p class="ptext">User Name</p>
<input type="text" name="uname" value="<?php echo $ffname. " ". $llname; ?>">
</div>
<section class="form-cont">
<div class="col1">
<div class="fname">
<p class="ptext">First Name</p>
<input type="text" name="fname" value="<?php echo $ffname; ?>">
</div>
<div class="gender">
<p class="ptext">Gender</p>
<div class="select-gen">
<input type="radio" name="gender" value="male"> Male
<input type="radio" name="gender" value="female"> Female
</div>
</div>
<div class="location">
<p class="ptext">Location</p>
<input type="text" name="location">
</div>
<div class="resphone">
<p class="ptext">Res. Phone:</p>
<input type="text" name="resphone" value="01-4289511">
</div>
<div class="about-you">
<p class="ptext">About You</p>
<input type="text" class="about" name="aboutyou">
</div>
<input type="hidden" name="uid" value="<?php echo $uid; ?>">
<button name="profiles" type="submit">Save</button>
</div>
<div class="col22">
<div class="lname">
<p class="ptext">Last Name</p>
<input type="text" name="lname" value="<?php echo $llname; ?>">
</div>
<div class="birthdate">
<p class="ptext">BirthDate</p>
<input type="text" name="bdate" >
</div>
<div class="email">
<p class="ptext">Email</p>
<input type="email" name="email" value="<?php echo $eemail; ?>">
</div>
<div class="mobile">
<p class="ptext">Mobile</p>
<input type="text" name="phone" value="<?php echo $mmobile; ?>">
</div>
</div>
</section>
</form>
</div>
</section>
<script>
function openForm() {
document.getElementById("myForm").style.display = "block";
}
function closeForm() {
document.getElementById("myForm").style.display = "none";
}
</script>
<script>
let tablinks = document.getElementsByClassName('tab-links');
let tabcontents = document.getElementsByClassName('tab-contents');
function opentab(tabname){
for(tablink of tablinks){
tablink.classList.remove("active-link");
}
for (tabcontent of tabcontents) {
tabcontent.classList.remove("active-tab");
}
event.currentTarget.classList.add("active-link");
document.getElementById(tabname).classList.add("active-tab")
}
</script>
</body>
</html>