prepare("SELECT * FROM users WHERE user_id = ?"); $stmt->execute([$_SESSION['user_id']]); $user = $stmt->fetch(); // Get recent orders $stmt = $pdo->prepare(" SELECT o.order_id, o.order_date, o.total_amount, o.status, o.pickup_schedule FROM orders o WHERE o.customer_id = ? ORDER BY o.order_date DESC LIMIT 5 "); $stmt->execute([$_SESSION['user_id']]); $orders = $stmt->fetchAll(); // Handle profile updates if ($_SERVER['REQUEST_METHOD'] === 'POST' && isset($_POST['update_profile'])) { $first_name = trim($_POST['first_name']); $last_name = trim($_POST['last_name']); $email = trim($_POST['email']); $phone = trim($_POST['phone']); $university_id = trim($_POST['university_id']); // Validate inputs if (empty($first_name) || empty($last_name) || empty($email) || empty($university_id)) { $error_message = 'Please fill in all required fields.'; } elseif (!filter_var($email, FILTER_VALIDATE_EMAIL)) { $error_message = 'Please enter a valid email address.'; } else { try { // Check if email is already taken by another user $stmt = $pdo->prepare("SELECT user_id FROM users WHERE email = ? AND user_id != ?"); $stmt->execute([$email, $_SESSION['user_id']]); if ($stmt->fetch()) { $error_message = 'This email is already registered to another account.'; } else { // Update profile $stmt = $pdo->prepare(" UPDATE users SET first_name = ?, last_name = ?, email = ?, phone = ?, university_id = ? WHERE user_id = ? "); $stmt->execute([ $first_name, $last_name, $email, $phone, $university_id, $_SESSION['user_id'] ]); $success_message = 'Profile updated successfully!'; // Refresh user data $stmt = $pdo->prepare("SELECT * FROM users WHERE user_id = ?"); $stmt->execute([$_SESSION['user_id']]); $user = $stmt->fetch(); } } catch (PDOException $e) { $error_message = 'An error occurred while updating your profile. Please try again.'; } } } // Handle password changes if ($_SERVER['REQUEST_METHOD'] === 'POST' && isset($_POST['change_password'])) { $current_password = $_POST['current_password']; $new_password = $_POST['new_password']; $confirm_password = $_POST['confirm_password']; if (empty($current_password)) { $error_message = 'Please enter your current password.'; } elseif (empty($new_password) || empty($confirm_password)) { $error_message = 'Please enter and confirm your new password.'; } elseif ($new_password !== $confirm_password) { $error_message = 'New passwords do not match.'; } elseif (strlen($new_password) < 8) { $error_message = 'Password must be at least 8 characters long.'; } else { // Verify current password $stmt = $pdo->prepare("SELECT password FROM users WHERE user_id = ?"); $stmt->execute([$_SESSION['user_id']]); $db_password = $stmt->fetchColumn(); if (password_verify($current_password, $db_password)) { // Update password $hashed_password = password_hash($new_password, PASSWORD_DEFAULT); $stmt = $pdo->prepare("UPDATE users SET password = ? WHERE user_id = ?"); $stmt->execute([$hashed_password, $_SESSION['user_id']]); $success_message = 'Password changed successfully!'; } else { $error_message = 'Current password is incorrect.'; } } } ?>
Member since
You haven't placed any orders yet.
| Order ID | Date | Amount | Status | Pickup Schedule |
|---|---|---|---|---|
| # | ₱ |