35995-vm/edit.php
Flatlogic Bot fd6af01e3c v1
2025-11-22 11:23:43 +00:00

99 lines
4.4 KiB
PHP

<?php
require_once 'db/config.php';
session_start();
$registration = null;
$error = '';
if (isset($_GET['token'])) {
$token = $_GET['token'];
$pdo = db();
$stmt = $pdo->prepare('SELECT * FROM registrations WHERE edit_token = ?');
$stmt->execute([$token]);
$registration = $stmt->fetch();
if (!$registration) {
$error = 'Invalid registration token.';
}
} else {
$error = 'No token provided.';
}
if ($_SERVER['REQUEST_METHOD'] === 'POST' && $registration) {
$fullname = trim($_POST['fullname'] ?? '');
$email = trim($_POST['email'] ?? '');
$mobile_no = trim($_POST['mobile_no'] ?? '');
$job_description = trim($_POST['job_description'] ?? '');
if (empty($fullname) || empty($email) || empty($mobile_no)) {
$error = 'Full Name, Email, and Mobile Number are required.';
} elseif (!filter_var($email, FILTER_VALIDATE_EMAIL)) {
$error = 'Invalid email format.';
} else {
try {
$stmt = $pdo->prepare(
'UPDATE registrations SET fullname = ?, email = ?, mobile_no = ?, job_description = ? WHERE id = ?'
);
$stmt->execute([$fullname, $email, $mobile_no, $job_description, $registration['id']]);
$_SESSION['success_message'] = 'Registration updated successfully!';
header('Location: index.php');
exit;
} catch (PDOException $e) {
error_log($e->getMessage());
$error = 'An error occurred while updating.';
}
}
}
?>
<!DOCTYPE html>
<html lang="en">
<head>
<meta charset="UTF-8">
<meta name="viewport" content="width=device-width, initial-scale=1.0">
<title>Edit Registration</title>
<link href="https://cdn.jsdelivr.net/npm/bootstrap@5.3.2/dist/css/bootstrap.min.css" rel="stylesheet">
<link href="assets/css/custom.css" rel="stylesheet">
</head>
<body>
<div class="container mt-5">
<div class="row justify-content-center">
<div class="col-md-8">
<div class="card">
<div class="card-header gradient-header">
<h4>Edit Registration</h4>
</div>
<div class="card-body">
<?php if ($error): ?>
<div class="alert alert-danger"><?php echo htmlspecialchars($error); ?></div>
<?php endif; ?>
<?php if ($registration): ?>
<form action="edit.php?token=<?php echo htmlspecialchars($token); ?>" method="POST" class="needs-validation" novalidate>
<div class="mb-3">
<label for="fullname" class="form-label">Full Name</label>
<input type="text" class="form-control" id="fullname" name="fullname" value="<?php echo htmlspecialchars($registration['fullname']); ?>" required>
</div>
<div class="mb-3">
<label for="email" class="form-label">Email address</label>
<input type="email" class="form-control" id="email" name="email" value="<?php echo htmlspecialchars($registration['email']); ?>" required>
</div>
<div class="mb-3">
<label for="mobile_no" class="form-label">Mobile Number</label>
<input type="text" class="form-control" id="mobile_no" name="mobile_no" value="<?php echo htmlspecialchars($registration['mobile_no']); ?>" required>
</div>
<div class="mb-3">
<label for="job_description" class="form-label">Job Description</label>
<textarea class="form-control" id="job_description" name="job_description" rows="3"><?php echo htmlspecialchars($registration['job_description']); ?></textarea>
</div>
<button type="submit" class="btn btn-primary">Update Registration</button>
<a href="index.php" class="btn btn-secondary">Cancel</a>
</form>
<?php endif; ?>
</div>
</div>
</div>
</div>
</div>
<script src="https://cdn.jsdelivr.net/npm/bootstrap@5.3.2/dist/js/bootstrap.bundle.min.js"></script>
</body>
</html>