-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathprofilesave.php
63 lines (55 loc) · 2.05 KB
/
profilesave.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
<?php
include_once('includes/secure.php');
include_once('includes/dbconfig.php');
$firstname = $_POST['firstname'];
$lastname = $_POST['lastname'];
$password = $_POST['password'];
$user = $_SESSION['username'];
if ($password == "" || empty($password)){
$sql = "UPDATE users SET firstname='$firstname', lastname='$lastname' WHERE username='$user'";
if ($conn->query($sql) === TRUE) {
$sql = "SELECT * FROM users WHERE username='$user' LIMIT 1";
$result = $conn->query($sql);
if ($result->num_rows > 0) {
// output data of each row
while($row = $result->fetch_assoc()) {
//Update session data
$_SESSION['firstname'] = $row['firstname'];
$_SESSION['lastname'] = $row['lastname'];
$_SESSION['admin'] = $row['admin'];
header('location: ./index.php?a=profilesaved');
die();
}
//Reload session variables ends
echo '<br><a href="index.php">Return to main site</a>';
}} else {
echo "Error updating record: " . $conn->error;
echo '<br><a href="index.php">Return to main site</a>';
}
} else {
$param_password = password_hash($password, PASSWORD_DEFAULT); // Creates a password hash
$sql = "UPDATE users SET firstname='$firstname', lastname='$lastname', password='$param_password' WHERE username='$user'";
if ($conn->query($sql) === TRUE) {
$sql = "SELECT * FROM users WHERE username='$user' LIMIT 1";
$result = $conn->query($sql);
if ($result->num_rows > 0) {
// output data of each row
while($row = $result->fetch_assoc()) {
//Update session data
$_SESSION['firstname'] = $row['firstname'];
$_SESSION['lastname'] = $row['lastname'];
$_SESSION['admin'] = $row['admin'];
header('location: ./index.php?a=profilepasswordsaved');
die();
}
//Reload session variables ends
echo '<br><a href="index.php">Return to main site</a>';
}} else {
echo "Error updating record: " . $conn->error;
echo '<br><a href="index.php">Return to main site</a>';
}
}
$conn->close();
?>
</body>
</html>