I'm in a rush to release so I am adding features that are needed to make it usable.
This commit is contained in:
parent
c76ab1abf3
commit
4c2857b445
25 changed files with 2475 additions and 3475 deletions
43
update_name.php
Normal file
43
update_name.php
Normal file
|
@ -0,0 +1,43 @@
|
|||
<?php
|
||||
session_start();
|
||||
require_once 'includes/globals.php';
|
||||
require_once 'vendor/autoload.php';
|
||||
|
||||
use DJMixHosting\Database;
|
||||
|
||||
// Ensure the user is logged in
|
||||
if (!isset($_SESSION['user'])) {
|
||||
header("Location: login.php");
|
||||
exit;
|
||||
}
|
||||
|
||||
// Check that both first and last names were provided
|
||||
if ($_SERVER['REQUEST_METHOD'] !== 'POST' || empty($_POST['first_name']) || empty($_POST['last_name'])) {
|
||||
$_SESSION['error'] = "Both first name and last name are required.";
|
||||
header("Location: profile.php");
|
||||
exit;
|
||||
}
|
||||
|
||||
$firstName = trim($_POST['first_name']);
|
||||
$lastName = trim($_POST['last_name']);
|
||||
|
||||
$db = new Database($config);
|
||||
$userId = $_SESSION['user']['id'];
|
||||
|
||||
// Update the user's first and last name in the database
|
||||
$stmt = $db->prepare("UPDATE users SET firstName = ?, lastName = ? WHERE id = ?");
|
||||
$stmt->bind_param("ssi", $firstName, $lastName, $userId);
|
||||
if (!$stmt->execute()) {
|
||||
$_SESSION['error'] = "Failed to update name. Please try again.";
|
||||
header("Location: profile.php");
|
||||
exit;
|
||||
}
|
||||
$stmt->close();
|
||||
|
||||
// Optionally update session data if you store these fields there
|
||||
$_SESSION['user']['firstName'] = $firstName;
|
||||
$_SESSION['user']['lastName'] = $lastName;
|
||||
|
||||
$_SESSION['success'] = "Name updated successfully.";
|
||||
header("Location: profile.php");
|
||||
exit;
|
Loading…
Add table
Add a link
Reference in a new issue