-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathtambahkereta.php
More file actions
32 lines (27 loc) · 835 Bytes
/
tambahkereta.php
File metadata and controls
32 lines (27 loc) · 835 Bytes
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
<?php
include("config.php");
// cek apakah tombol di form sudah diklik atau belum
if(isset($_POST['tambahkereta'])){
// ambil data dari formulir
$nama_kereta = $_POST['nama_kereta'];
$kapasitas = $_POST['kapasitas'];
$operasional = $_POST['operasional'];
if ($operasional === 'Ya'){
$operasional = 'true';
} elseif ($operasional === 'Tidak') {
$operasional = 'false';
}
// buat query
$query = pg_query("INSERT INTO kereta (nama, beroperasi, kapasitas) VALUEs ('$nama_kereta', $operasional, $kapasitas)");
// apakah query simpan berhasil?
if( $query==TRUE ) {
// kalau berhasil alihkan ke halaman index.php
header('Location: index.php');
} else {
// kalau gagal kembalikan ke halaman form
header('Location: tambahkereta_page.php');
}
} else {
die("Akses dilarang...");
}
?>