-
Notifications
You must be signed in to change notification settings - Fork 1
/
Copy pathpayment.php
119 lines (103 loc) · 3.83 KB
/
payment.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
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
<?php
include "db.php";
session_start();
if(isset($_POST["submit"])){
$nama = $_POST["nama"];
$alamat = $_POST["alamat"];
$telp = $_POST["telepon"];
$pengiriman = $_POST["pengiriman"];
}
$listproduk = array();
if($pengiriman == "Antar"){
$txt_pengiriman = "Antar ke Rumah";
$ongkir = 8000;
} else {
$txt_pengiriman = "Ambil ke Cafe";
$ongkir = 0;
}
for($i = 0; $i < sizeof($_SESSION['beli']); $i++){
$produkcurr = $_SESSION['beli'][$i];
$sql_produk = "SELECT * FROM `produk` WHERE `namaProduk` = '$produkcurr'";
$result_produk = mysqli_query($conn, $sql_produk);
$data_produk = mysqli_fetch_assoc($result_produk);
array_push($listproduk, $data_produk);
}
$totalBiaya = array_column($listproduk, 'hargaProduk');
$totalBiaya = array_map('intval', $totalBiaya);
$produkId = array_column($listproduk, 'idProduk');
$sql = "INSERT INTO `riwayat`(`idRiwayat`, `namaPembeli`, `alamatPembeli`, `noTelp`, `pengiriman`) VALUES ('','$nama','$alamat','$telp','$pengiriman')";
$result = mysqli_query($conn, $sql);
$sql_riwayat = "SELECT * FROM `riwayat` WHERE `namaPembeli` = '$nama'";
$result_riwayat = mysqli_query($conn, $sql_riwayat);
$data_riwayat = mysqli_fetch_assoc($result_riwayat);
$id_riwayat = $data_riwayat['idRiwayat'];
foreach($produkId as $data){
$insert = "INSERT INTO `riwayat_produk`(`Riwayat_idRiwayat`, `Produk_idProduk`) VALUES ('$id_riwayat','$data')";
$result = mysqli_query($conn, $insert);
}
?>
<!DOCTYPE html>
<html lang="en">
<head>
<meta charset="UTF-8">
<meta http-equiv="X-UA-Compatible" content="IE=edge">
<meta name="viewport" content="width=device-width, initial-scale=1.0">
<link href="assets/css/style.css" rel="stylesheet">
<title>Terima Kasih!</title>
</head>
<body>
<header class="header" id="header">
<div class="navbar-container">
<h1 class="logo">KiCoffee</h1>
<nav class="navbar">
<ul>
<li><a href="./index2.html" class="nav-link">Home</a></li>
</ul>
</nav>
</div>
</header>
<section id=pay>
<div class="row">
<div class="col-sm-6">
<div class="card">
<div class="card-body">
<h5 class="card-title">Pesanan Untuk :</h5>
<h1><?php echo $nama ?></h1>
<p>Di <strong><?php echo $alamat ?></strong></p>
<p>Metode pengiriman yang diinginkan adalah <strong><?php echo $txt_pengiriman; ?></strong></p>
<p>Nomor yang dapat dihubungi adalah <strong><?php echo $telp ?></strong></p>
</div>
</div>
</div>
<div class="col-sm-6">
<div class="card">
<div class="card-body">
<h5>Daftar Pesanan :</h5>
<table style="margin-left:auto;margin-right:auto" border="3">
<tr>
<th>Nama Produk</th>
<th>Harga Produk</th>
</tr>
<?php
foreach($listproduk as $row){
?>
<tr>
<td><?php echo $row['namaProduk']; ?></td>
<td><?php echo $row['hargaProduk']; ?></td>
</tr>
<?php
}
?>
<tr>
<th>Total:</th>
<td><?php echo array_sum($totalBiaya) + $ongkir; ?></td>
</tr>
</table><br>
<a href="cart.php" class="btn btn-primary">Selesai</a>
</div>
</div>
</div>
</div>
</section>
</body>
</html>