-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathprofile.php
163 lines (113 loc) · 4.55 KB
/
profile.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
<?php
session_start();
// If user directly open homepage url without login, it will redirect to index.html.
if($_SESSION['userid'] == ''){
header("Location: index.html");
die();
}
?>
<?php
include('config.php');
$profileUserID = $_SESSION['userid'];
$profilequery = "select * from users where user_id= '$profileUserID' ";
$profileResult = mysqli_query($conn, $profilequery);
$profileRow = mysqli_fetch_array($profileResult, MYSQLI_ASSOC); // has array value of that matched row.
$profileCount = mysqli_num_rows($profileResult); // for checking that match email is present in a row or not
if($profileCount){
?>
<!DOCTYPE html>
<html>
<head>
<meta charset="UTF-8">
<meta http-equiv="X-UA-Compatible" content="IE=edge">
<meta name="viewport" content="width=device-width, initial-scale=1.0">
<link href="https://cdn.jsdelivr.net/npm/bootstrap@5.2.0/dist/css/bootstrap.min.css" rel="stylesheet"
integrity="sha384-gH2yIJqKdNHPEq0n4Mqa/HGKIhSkIHeL5AyhkYV8i59U5AR6csBvApHHNl/vI1Bx" crossorigin="anonymous">
<link rel="stylesheet" href="./style.css">
<link rel="stylesheet" href="./#.css">
<title>Railway System</title>
</head>
<body>
<!-- Navbar -->
<nav class="navbar navbar-expand-lg bg-success shadow ">
<div class="container ">
<a class="navbar-brand " href="#">
<img src="./images/logo.png" alt="RailwayLogo" width="60">
</a>
<button class="navbar-toggler" type="button" data-bs-toggle="collapse" data-bs-target="#navbarSupportedContent"
aria-controls="navbarSupportedContent" aria-expanded="false" aria-label="Toggle navigation">
<span class="navbar-toggler-icon"></span>
</button>
<div class="collapse navbar-collapse" id="navbarSupportedContent">
<ul class="navbar-nav me-auto mb-2 mb-lg-0">
<li class="nav-item">
<a class="nav-link" aria-current="page" href="./homepage.php">Home</a>
</li>
<li class="nav-item">
<a class="nav-link active" href="./profile.php">My Profile</a>
</li>
<li class="nav-item ">
<a class="nav-link" href="./booking.php">Booking</a>
</li>
<li class="nav-item ">
<a class="nav-link" href="logout.php">Logout</a>
</li>
</ul>
</div>
</div>
</nav>
<!-- ------------------------ -->
<!-- Form -->
<div class="global-container">
<div class="card login-form">
<div class="card-body d-flex flex-column justify-content-center">
<h3 class="card-title text-center">My Profile</h3>
<div class="card-text">
<form action="" method="POST">
<div class="form-group">
<label for="Name">Name</label>
<input type="text" class="form-control form-control-sm" id="Name" name="pname" value="<?php echo $profileRow['name']; ?>"
aria-describedby="emailHelp" >
</div>
<div class="form-group mt-3">
<label for="Email">Email address</label>
<input type="email" class="form-control form-control-sm" id="Email" name="pemail"
aria-describedby="emailHelp" value="<?php echo $profileRow['email']; ?>">
</div>
<div class="form-group mt-3">
<label for="Password">Password</label>
<input type="password" class="form-control form-control-sm" id="Password" name="password" value="<?php echo $profileRow['password']; ?>">
</div>
<button type="submit" class="btn btn-primary btn-block" name="updateProfile">Update Profile</button>
</form>
</div>
</div>
</div>
</div>
<!-- ------------------------------- -->
<?php
} // closing if condition curly braces here
if(isset($_POST['updateProfile'])){
$profileName = $_POST['pname'];
$profileEmail = $_POST['pemail'];
$profilePassword = $_POST['password'];
$userid = $profileRow['user_id'];
$profileUpdateQuery = "UPDATE users SET name='$profileName', email='$profileEmail', password='$profilePassword' where user_id ='$userid' ";
$profileUpdateResult = mysqli_query($conn, $profileUpdateQuery);
if($profileUpdateQuery){
header("Location: profile.php");
}
else{
?>
<script>
alert("Oops There some error!");
</script>
<?php
}
}
?>
<script src="https://cdn.jsdelivr.net/npm/bootstrap@5.2.0/dist/js/bootstrap.bundle.min.js"
integrity="sha384-A3rJD856KowSb7dwlZdYEkO39Gagi7vIsF0jrRAoQmDKKtQBHUuLZ9AsSv4jD4Xa"
crossorigin="anonymous"></script>
</body>
</html>