-
Notifications
You must be signed in to change notification settings - Fork 3
/
Copy pathserver.php
41 lines (34 loc) · 1.08 KB
/
server.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
<?php
// Session start & Connect the MySql
session_start();
$db = mysqli_connect("localhost", "root", "", "simple_crud");
// Initialize Variables
$nama = "";
$kota = "";
$id = 0;
$update = false;
// POST Add new data
if (isset($_POST['save'])) {
$nama = $_POST['nama'];
$kota = $_POST['kota'];
mysqli_query($db, "INSERT INTO user (nama, kota) VALUES ('$nama', '$kota')");
$_SESSION['alert'] = "Data saved!";
header("location: index.php");
}
// POST Update data
if (isset($_POST['update'])) {
$id = $_POST['id'];
$nama = $_POST['nama'];
$kota = $_POST['kota'];
mysqli_query($db, "UPDATE user SET nama='$nama', kota='$kota' WHERE id=$id");
$_SESSION['alert'] = "Data updated!";
header("location: index.php");
}
// GET Delete data
if (isset($_GET['del'])) {
$id = $_GET['del'];
mysqli_query($db, "DELETE FROM user WHERE id=$id");
$_SESSION['alert'] = "Data deleted!";
header("location: index.php");
}
?>