-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathprocesspelanggan.php
57 lines (49 loc) · 1.74 KB
/
processpelanggan.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
<?php
session_start();
include "koneksi.php";
$aksi = $_GET['act'];
if($aksi == "add") {
$nama = $_POST['nama'];
$alamat = $_POST['alamat'];
$nomer = $_POST['nomer'];
$merk = $_POST['merk'];
$tampil = "SELECT * FROM pelanggan WHERE nama_pelanggan='$nama'";
$qtampil = mysql_query($tampil);
if(mysql_num_rows($qtampil) > 0) {
$_SESSION['ada'] = 'sukses';
echo "<script>location.replace('datapelanggan.php');</script>";
} else {
$tambah = "INSERT INTO pelanggan VALUES(null, '$nama', '$alamat', '$nomer', '$merk')";
$qtambah = mysql_query($tambah);
$_SESSION['insert'] = 'sukses';
echo "<script>location.replace('datapelanggan.php');</script>";
}
} else if($aksi == "del") {
$id = $_GET['id'];
$hapus = "DELETE FROM pelanggan WHERE id_pelanggan='$id'";
$qhapus = mysql_query($hapus);
$_SESSION['delete'] = 'sukses';
echo "<script>location.replace('datapelanggan.php')</script>";
} else if($aksi == "update") {
$id = $_POST['idpel'];
$nama = $_POST['nama'];
$alamat = $_POST['alamat'];
$nomer = $_POST['nomer'];
$merk = $_POST['merk'];
$lama = $_POST['lama'];
$tampil = "SELECT * FROM pelanggan WHERE nama_pelanggan='$nama'";
$qtampil = mysql_query($tampil);
if(mysql_num_rows($qtampil) > 0 && $lama!=$nama) {
$_SESSION['ada'] = 'sukses';
echo "<script>location.replace('datapelanggan.php');</script>";
} else {
$tambah = "UPDATE pelanggan SET nama_pelanggan='$nama', alamat_pelanggan='$alamat',
nomer_hp='$nomer', id_merk='$merk' WHERE id_pelanggan='$id'";
$qtambah = mysql_query($tambah);
$_SESSION['update'] = 'sukses';
echo "<script>location.replace('datapelanggan.php');</script>";
}
} else {
echo "<script>location.replace('datapelanggan.php')</script>";
}
?>