/
Andreyrt
/
korochki
Обзор
Документация
Войти
/
Andreyrt
/
korochki
Код
Запросы
0
Задачи
Вики
Пакеты
0
Релизы
0
CI/CD
Аналитика
Безопасность
master
book.php
73 строки
3 KB
Andreyrt
Первая версия портала Корочки.есть
07 май 2026, 18:21
07 май 2026, 18:21
fd50aa7
Код
Авторство
О чём код?
<?php require_once 'config.php'; requireAuth(); $trainings = []; $res = $db->query("SELECT * FROM trainings"); while ($row = $res->fetchArray(SQLITE3_ASSOC)) $trainings[] = $row; if ($_SERVER['REQUEST_METHOD'] === 'POST') { $tid = (int)$_POST['training_id']; $date = $_POST['booking_date']; $time = $_POST['booking_time']; $pay = $_POST['payment_method']; if ($date < date('Y-m-d')) { flash('Дата не может быть в прошлом'); } else { $st = $db->prepare("INSERT INTO bookings (user_id,training_id,booking_date,booking_time,payment_method) VALUES(:u,:t,:d,:tm,:p)"); $st->bindValue(':u', $_SESSION['user_id'], SQLITE3_INTEGER); $st->bindValue(':t', $tid, SQLITE3_INTEGER); $st->bindValue(':d', $date); $st->bindValue(':tm', $time); $st->bindValue(':p', $pay); $st->execute(); flash('Запись создана!', 'success'); header('Location: my_bookings.php'); exit; } } ?> <!DOCTYPE html> <html lang="ru"> <head> <meta charset="UTF-8"> <meta name="viewport" content="width=device-width,initial-scale=1"> <title>Запись</title> <link rel="stylesheet" href="static/style.css"> </head> <body> <header><h1>Запись на тренировку</h1></header> <?php $f = getFlash(); if ($f): ?> <p class="<?= $f['type'] ?>"><?= htmlspecialchars($f['msg']) ?></p> <?php endif; ?> <form method="post"> <div class="form-group"> <label>Вид тренировки</label> <select name="training_id" required> <?php foreach ($trainings as $t): ?> <option value="<?= $t['id'] ?>"><?= htmlspecialchars($t['name']) ?></option> <?php endforeach; ?> </select> </div> <div class="form-group"> <label>Дата</label> <input type="date" name="booking_date" required> </div> <div class="form-group"> <label>Время</label> <input type="time" name="booking_time" required> </div> <div class="form-group"> <label>Оплата</label> <label><input type="radio" name="payment_method" value="наличные" checked> Наличные</label> <label><input type="radio" name="payment_method" value="карта в клубе"> Карта</label> </div> <button type="submit" class="btn">Записаться</button> </form> <p><a href="my_bookings.php">Мои записи</a> | <a href="logout.php">Выход</a></p> </body> </html>