-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathcreate.php
78 lines (67 loc) · 2.72 KB
/
create.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
<!DOCTYPE html>
<html>
<head>
<title>Form Pendaftaran Peserta</title>
<link rel="stylesheet" href="https://cdn.jsdelivr.net/npm/[email protected]/dist/css/bootstrap.min.css" integrity="sha384-zCbKRCUGaJDkqS1kPbPd7TveP5iyJE0EjAuZQTgFLD2ylzuqKfdKlfG/eSrtxUkn" crossorigin="anonymous">
</head>
<body>
<div class="container">
<?php
//Include file koneksi, untuk koneksikan ke database
include "koneksi.php";
//Fungsi untuk mencegah inputan karakter yang tidak sesuai
function input($data) {
$data = trim($data);
$data = stripslashes($data);
$data = htmlspecialchars($data);
return $data;
}
//Cek apakah ada kiriman form dari method post
if ($_SERVER["REQUEST_METHOD"] == "POST") {
$nama=input($_POST["nama"]);
$sekolah=input($_POST["sekolah"]);
$jurusan=input($_POST["jurusan"]);
$no_hp=input($_POST["no_hp"]);
$alamat=input($_POST["alamat"]);
//Query input menginput data kedalam tabel anggota
$sql="insert into peserta (nama,sekolah,jurusan,no_hp,alamat) values
('$nama','$sekolah','$jurusan','$no_hp','$alamat')";
//Mengeksekusi/menjalankan query diatas
$hasil=mysqli_query($kon,$sql);
//Kondisi apakah berhasil atau tidak dalam mengeksekusi query diatas
if ($hasil) {
header("Location:index.php");
}
else {
echo "<div class='alert alert-danger'> Data Gagal disimpan.</div>";
}
}
?>
<h2>Input Data</h2>
<form action="<?php echo $_SERVER["PHP_SELF"];?>" method="post">
<div class="form-group">
<label>Nama:</label>
<input type="text" name="nama" class="form-control" placeholder="Masukan Nama" required />
</div>
<div class="form-group">
<label>Sekolah:</label>
<input type="text" name="sekolah" class="form-control" placeholder="Masukan Nama Sekolah" required/>
</div>
<div class="form-group">
<label>Jurusan :</label>
<input type="text" name="jurusan" class="form-control" placeholder="Masukan Jurusan" required/>
</div>
</p>
<div class="form-group">
<label>No HP:</label>
<input type="text" name="no_hp" class="form-control" placeholder="Masukan No HP" required/>
</div>
<div class="form-group">
<label>Alamat:</label>
<textarea name="alamat" class="form-control" rows="5"placeholder="Masukan Alamat" required></textarea>
</div>
<button type="submit" name="submit" class="btn btn-primary">Submit</button>
</form>
</div>
</body>
</html>