-
Notifications
You must be signed in to change notification settings - Fork 2
/
addbeach.php
134 lines (122 loc) · 5.32 KB
/
addbeach.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
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
<?php
require_once('./layouts/header.php');
session_start();
if ($_SESSION['role'] == "user") {
header('location: index.php');
exit();
}
if ($_SERVER['REQUEST_METHOD'] === 'POST') {
$name = $_POST['name'];
$description = $_POST['description'];
if (isset($_FILES['image']) && $_FILES['image']['error'] === UPLOAD_ERR_OK) {
$image_tmp = $_FILES['image']['tmp_name'];
$image_name = $_FILES['image']['name'];
if (move_uploaded_file($image_tmp, $image_name)) {
$sql = "INSERT INTO beaches (beaches_name, beaches_description, regions_id, beaches_img) VALUES ('$name', '$description', '1', './assets/$image_name')";
$res = $conn->query($sql);
if ($res) {
header('Location: admin.php');
exit();
} else {
echo 'Error: ' . $conn->error;
}
} else {
echo 'Error: Failed to move the uploaded image.';
}
}
}
$conn->close();
?>
<!DOCTYPE html>
<html lang="en">
<head>
<link rel="stylesheet" href="./assets/css/editbeach.css">
</head>
<body>
<div class="card">
<div class="card-header d-flex align-items-center justify-content-between">
<h3 class="text-center">Add Beach Page</h3>
<?php
$cookieData = json_decode($_COOKIE['user'], true);
$username = $cookieData['username'];
echo '<div class="d-flex align-items-center text-align-center">';
echo '<div>Hello Admin <h3>' . $username . '</h3></div>';
echo '<button onclick="dologout(event)" class="btn lout btn-primary">Logout</button>';
echo '</div>';
?>
</div>
<div class="page-wrap d-flex" style="margin-top:10px">
<div class="content-1">
<div class="control-wrap">
<h2 style="background-color: gray;">Admin Menu</h2>
<ul>
<li><a href="#">Admin</a></li>
<li><a href="#">Customer</a></li>
<li><a href="../beaches.php">Beachs</a></li>
<li><a href="contact.php">Contact</a></li>
<li><a href="feedback.php">Feedback</a></li>
<li><a href="#">Cart</a></li>
</ul>
</div>
</div>
<div class="content-2">
<div class="d-flex align-items-center justify-content-between mb-2">
<div>
<div class="title_editbeach" style="background-color: gray;">
<h2 style="margin-bottom: 50px;margin-left:43%;">Add Beach</h2>
</div>
<form method="POST" action="" enctype="multipart/form-data">
<div class="form-group">
<label for="name">Beach Name</label>
<input type="text" name="name" id="name" required>
</div>
<div class="form-group">
<label for="description">Beach Description</label>
<textarea name="description" id="description" required></textarea>
</div>
<div class="form-group">
<label for="regions">Regions</label>
<select name="regions" id="regions" required>
<option value="">Select a Regions</option>
<option value="3">East</option>
<option value="1">West</option>
<option value="4">Southern</option>
<option value="2">North</option>
</select>
</div>
<div class="form-group d-flex">
<label for="image">Beach Image</label>
<input type="file" name="image" id="image" accept="image/*" required>
<img id="preview-image" src="#" alt="Preview Image"
style="display: none; max-width: 200px; margin-top: 10px;">
</div>
<div class="form-group">
<label for=""></label>
<button type="submit" class="btn btn-primary">Add Beach</button>
</div>
</form>
</div>
</div>
</div>
</div>
</div>
</body>
<script>
function dologout(e) {
e.preventDefault();
if (confirm('Bạn có muốn đăng xuất không?')) {
window.location.href = '../logout.php';
}
}
document.getElementById('image').addEventListener('change', function (e) {
var file = e.target.files[0];
var reader = new FileReader();
reader.onload = function (e) {
var imagePreview = document.getElementById('preview-image');
imagePreview.src = e.target.result;
imagePreview.style.display = 'block';
};
reader.readAsDataURL(file);
});
</script>
</html>