132 lines
4.3 KiB
PHP
132 lines
4.3 KiB
PHP
<?php
|
|
require_once 'db/config.php';
|
|
|
|
$id = $_GET['id'] ?? null;
|
|
if (!$id) {
|
|
header("Location: admin_exercises.php");
|
|
exit;
|
|
}
|
|
|
|
// Handle form submission for updating an exercise
|
|
if ($_SERVER['REQUEST_METHOD'] === 'POST' && isset($_POST['update_exercise'])) {
|
|
$name = $_POST['name'];
|
|
$description = $_POST['description'];
|
|
$video_url = $_POST['video_url'];
|
|
$muscle_group = $_POST['muscle_group'];
|
|
|
|
if (!empty($name)) {
|
|
$stmt = db()->prepare("UPDATE exercises SET name = ?, description = ?, video_url = ?, muscle_group = ? WHERE id = ?");
|
|
$stmt->execute([$name, $description, $video_url, $muscle_group, $id]);
|
|
}
|
|
header("Location: admin_exercises.php");
|
|
exit;
|
|
}
|
|
|
|
// Fetch the exercise
|
|
$stmt = db()->prepare("SELECT * FROM exercises WHERE id = ?");
|
|
$stmt->execute([$id]);
|
|
$exercise = $stmt->fetch();
|
|
|
|
if (!$exercise) {
|
|
header("Location: admin_exercises.php");
|
|
exit;
|
|
}
|
|
?>
|
|
<!DOCTYPE html>
|
|
<html lang="en">
|
|
<head>
|
|
<meta charset="UTF-8">
|
|
<meta name="viewport" content="width=device-width, initial-scale=1.0">
|
|
<title>Edit Exercise</title>
|
|
<link href="https://fonts.googleapis.com/css2?family=Inter:wght@400;500;600;700&display=swap" rel="stylesheet">
|
|
<link rel="stylesheet" href="assets/css/custom.css">
|
|
<style>
|
|
body {
|
|
font-family: 'Inter', sans-serif;
|
|
background-color: #f8fafc;
|
|
color: #0f172a;
|
|
}
|
|
.container {
|
|
max-width: 1024px;
|
|
margin: 0 auto;
|
|
padding: 2rem;
|
|
}
|
|
h1 {
|
|
font-size: 2.25rem;
|
|
font-weight: 700;
|
|
margin-bottom: 2rem;
|
|
}
|
|
.card {
|
|
background-color: #ffffff;
|
|
border-radius: 0.5rem;
|
|
box-shadow: 0 4px 6px -1px rgb(0 0 0 / 0.1), 0 2px 4px -2px rgb(0 0 0 / 0.1);
|
|
padding: 2rem;
|
|
}
|
|
.form-group {
|
|
margin-bottom: 1.5rem;
|
|
}
|
|
.form-group label {
|
|
display: block;
|
|
font-weight: 500;
|
|
margin-bottom: 0.5rem;
|
|
}
|
|
.form-group input,
|
|
.form-group textarea {
|
|
width: 100%;
|
|
padding: 0.75rem;
|
|
border: 1px solid #e2e8f0;
|
|
border-radius: 0.375rem;
|
|
}
|
|
.btn {
|
|
background-color: #14b8a6;
|
|
color: #ffffff;
|
|
padding: 0.75rem 1.5rem;
|
|
border: none;
|
|
border-radius: 0.375rem;
|
|
font-weight: 600;
|
|
cursor: pointer;
|
|
transition: background-color 0.3s;
|
|
}
|
|
.btn:hover {
|
|
background-color: #0d9488;
|
|
}
|
|
.btn-secondary {
|
|
background-color: #f1f5f9;
|
|
color: #0f172a;
|
|
margin-left: 1rem;
|
|
}
|
|
.btn-secondary:hover {
|
|
background-color: #e2e8f0;
|
|
}
|
|
</style>
|
|
</head>
|
|
<body>
|
|
<div class="container">
|
|
<h1>Edit Exercise</h1>
|
|
|
|
<div class="card">
|
|
<form action="admin_edit_exercise.php?id=<?php echo $exercise['id']; ?>" method="POST">
|
|
<div class="form-group">
|
|
<label for="name">Exercise Name</label>
|
|
<input type="text" id="name" name="name" value="<?php echo htmlspecialchars($exercise['name']); ?>" required>
|
|
</div>
|
|
<div class="form-group">
|
|
<label for="description">Description</label>
|
|
<textarea id="description" name="description" rows="4"><?php echo htmlspecialchars($exercise['description']); ?></textarea>
|
|
</div>
|
|
<div class="form-group">
|
|
<label for="video_url">Video URL</label>
|
|
<input type="text" id="video_url" name="video_url" value="<?php echo htmlspecialchars($exercise['video_url']); ?>">
|
|
</div>
|
|
<div class="form-group">
|
|
<label for="muscle_group">Muscle Group</label>
|
|
<input type="text" id="muscle_group" name="muscle_group" value="<?php echo htmlspecialchars($exercise['muscle_group']); ?>">
|
|
</div>
|
|
<button type="submit" name="update_exercise" class="btn">Update Exercise</button>
|
|
<a href="admin_exercises.php" class="btn btn-secondary">Cancel</a>
|
|
</form>
|
|
</div>
|
|
</div>
|
|
</body>
|
|
</html>
|