-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathprofile.php
More file actions
37 lines (28 loc) · 1.03 KB
/
Copy pathprofile.php
File metadata and controls
37 lines (28 loc) · 1.03 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
<?php
session_start();
$servername = "localhost";
$username = "root";
$password = "";
$dbname = "used_clothing_marketplace";
$db = new mysqli($servername, $username, $password, $dbname);
if ($db->connect_error) {
die("Connection failed: " . $db->connect_error);
}
if (!isset($_SESSION['user_id'])) {
echo "<script>alert('login is needed.'); window.location.href = 'login.html';</script>";
exit();
}
$user_id = $_SESSION['user_id'];
if ($_SERVER["REQUEST_METHOD"] == "POST") {
$name = $db->real_escape_string($_POST['name']);
$email = $db->real_escape_string($_POST['email']);
$password = $_POST['password'] ? password_hash($_POST['password'], PASSWORD_DEFAULT) : null;
$query = "UPDATE users SET name = '$name', email = '$email', password = '$password' WHERE id = '$user_id'";
if ($db->query($query) === TRUE) {
echo "<script>alert('profile is successfully updated.'); window.location.href = 'main.html';</script>";
} else {
echo "<script>alert('error.');</script>";
}
}
$db->close();
?>