-
Notifications
You must be signed in to change notification settings - Fork 0
/
editProfile.php
executable file
·137 lines (108 loc) · 3.11 KB
/
editProfile.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
<?php
session_start();
error_reporting(E_ERROR);
include('dbconfig.php');
if (empty($_SESSION['id'])){
header('location:customerlogin.php');
}
if(isset($_POST['buttonUpdate'])){
if(empty($_POST['username'])){
$sweet = 'error';
$feedback = 'Provide a username';
}else{
$username = $_POST['username'];
if(empty($_POST['password'])){
$sweet = 'error';
$feedback = 'Provide a valid password';
}elseif(strlen(trim($_POST["password"])) < 6){
$sweet = 'error';
$feedback = 'Must have six characters';
}else{
$password = $_POST['password'];
if(empty($_POST['cpassword'])){
$sweet = 'error';
$feedback = 'PLease confirm your password';
}else{
$cpassword = $_POST['cpassword'];
if(empty($sweet) && ($password != $cpassword)){
$sweet = 'Your passwords do not match';
}else{
$update = "UPDATE `users` SET `username` = '$username', `password`='$password' WHERE `id` = '".$_SESSION['id']."'";
if(mysqli_prepare($conn, $update)){
// Bind variables to the prepared statement as parameters
mysqli_stmt_bind_param($stmt, "ss", $param_username, $param_password);
//set parameters
$sweet = 'success';
$feedback = 'Your Profile was updates successfully';
header('Location:customerDashBoard.php');
}else{
$sweet = 'success';
$feedback = 'Failed to update your profile';
}
}
}
}
}
}
?>
<!DOCTYPE html>
<html>
<head>
<meta charset="utf-8">
<title>Edit Proflie | Customer</title>
<link href="css/bootstrap.min.css" type="text/css" rel="stylesheet">
<link href="css/sweetalert.css" type="text/css" rel="stylesheet">
<script src="js/jquery.js"></script>
<script src="js/sweetalert.js"></script>
<script src="js/bootstrap.min.js"></script>
</head>
<body>
<!-- ERROR MESSEGES USING PHP AND SWEET ALERTS -->
<?php
if ($sweet=='error'){
echo"<script>
swal('Error','".$feedback."')
</script>";
}elseif($sweet=='success'){
echo"<script>
swal('Success','".$feedback."')
</script>";
}
?>
<div class="container">
<div class="jumbotron">
<div class="row" >
<div class="col-lg-4 col-md-4">
<a href="customerDashBoard.php" class="btn btn-primary btn-sm">Back to profile</a>
</div>
<div class="col-md-2 col-lg-2 col-sm-12">
<?php
$select="SELECT * FROM users WHERE id='".$_SESSION['id']."'";
$record=mysqli_query($conn,$select);
$row=mysqli_fetch_array($record);
?>
<form method="POST" autocomplete="off">
<label >Username</label>
<input type="text" name="username" class="form-control" value="<?php echo $row['username'] ?>">
</div>
<div class="col-md-2 col-lg-2 col-sm-12" style="background-color: aliceblue">
<label>Password</label>
<input type="password" name="password" class="form-control"value="<?php echo $row['password'] ?>">
</div>
</div>
<div class="row" >
<div class="col-lg-4 col-md-4">
</div>
<div class="col-md-3 col-lg-4 col-sm-12">
<label> Confirm Password</label>
<input type="password" name="cpassword" class="form-control" value="<?php echo $row['cpassword'] ?>">
<input type="submit" name="buttonUpdate" value="Update Account" class="form-control btn-info">
<br/>
</form>
</div>
</div>
</div>
</div>
</div>
</body>
</html>