-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathupdate_profile.php
More file actions
27 lines (24 loc) · 856 Bytes
/
update_profile.php
File metadata and controls
27 lines (24 loc) · 856 Bytes
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
<?php
session_start();
require_once 'includes/db.php';
if (!isset($_SESSION['user'])) {
header('Location: login.php');
exit();
}
if ($_SERVER['REQUEST_METHOD'] === 'POST') {
$first_name = trim($_POST['first_name'] ?? '');
$last_name = trim($_POST['last_name'] ?? '');
$address = trim($_POST['address'] ?? '');
$phone = trim($_POST['phone'] ?? '');
$stmt = $pdo->prepare('UPDATE users SET first_name = ?, last_name = ?, address = ?, phone = ? WHERE email = ?');
if ($stmt->execute([$first_name, $last_name, $address, $phone, $_SESSION['user']])) {
$_SESSION['profile_update_msg'] = 'Profile updated successfully!';
} else {
$_SESSION['profile_update_msg'] = 'Failed to update profile.';
}
header('Location: profile.php');
exit();
} else {
header('Location: profile.php');
exit();
}