-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathadd-school.php
34 lines (30 loc) · 1.08 KB
/
add-school.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
<?php
require('koneksi.php');
header('Content-Type: application/json');
if ($_SERVER["REQUEST_METHOD"] == "POST" && isset($_POST['schoolName']) && isset($_POST['schoolLocation']) && isset($_POST['schoolEmail']) && isset($_POST['schoolPhone'])) {
$schoolName = $_POST['schoolName'];
$schoolLocation = $_POST['schoolLocation'];
$schoolEmail = $_POST['schoolEmail'];
$schoolPhone = $_POST['schoolPhone'];
$sql = "INSERT INTO sekolah (nama, lokasi, email, no_telp) VALUES (?, ?, ?, ?)";
$stmt = $conn->prepare($sql);
$stmt->bind_param("ssss", $schoolName, $schoolLocation, $schoolEmail, $schoolPhone);
if ($stmt->execute()) {
echo json_encode([
'status' => 'success',
'message' => 'Mantap! Sekolah baru udah berhasil ditambahin nih'
]);
} else {
echo json_encode([
'status' => 'error',
'message' => 'Waduh, gagal nambah sekolah nih. Coba lagi deh!'
]);
}
$stmt->close();
} else {
echo json_encode([
'status' => 'error',
'message' => 'Invalid request'
]);
}
?>