-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathneworder.php
76 lines (68 loc) · 1.9 KB
/
neworder.php
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
<?php
session_start();
if (empty($_SESSION['user_id'])) {
header('Location:./login.php');
exit;
}
require_once(realpath(dirname(__FILE__)) . '/lib/db.php');
require_once(realpath(dirname(__FILE__)) . '/lib/user.php');
require_once(realpath(dirname(__FILE__)) . '/lib/order.php');
$connection = create_db_connection();
try {
$user = get_user($connection, $_SESSION['user_id']);
if (!$user) {
header('Location:./logout.php');
exit;
}
} catch (PDOException $e) {
header('Location:./logout.php');
exit;
}
?>
<?php if ($_SERVER['REQUEST_METHOD'] == 'POST') : ?>
<?php
if (isset($_POST['car_number']) && isset($_POST['description'])) {
try {
create_order($connection, [
'car_number' => $_POST['car_number'],
'description' => $_POST['description'],
]);
header('Location:./neworder.php');
} catch (PDOException $e) {
exit("Error: " . $e->getMessage());
}
}
?>
<?php else : ?>
<!DOCTYPE html>
<html lang="ru">
<head>
<meta charset="UTF-8">
<title>Написать заявление</title>
<link rel="stylesheet" href="./static/css/style.css">
</head>
<body>
<?php include("blocks/header.php"); ?>
<main class="neworder">
<div class="neworder__container">
<div class="neworder__body">
<form method="POST" action="neworder.php" class="neworder__form form">
<h2>Написать заявление</h2>
<div class="form__body">
<div class="form__block">
<label for="car_number">Номер машины</label>
<input class="input" name="car_number" type="text">
</div>
<div class="form__block">
<label for="description">Описание</label>
<textarea class="input" name="description" id="description" cols="30" rows="10"></textarea>
</div>
</div>
<button type="submit" class="form__btn btn">Отправить</button>
</form>
</div>
</div>
</main>
</body>
</html>
<?php endif; ?>