cluster 2 web e-commerce printer
koneksi.php
<?php
$db = mysqli_connect("localhost", "root", "", "clus1");
function beli($data){
global $db;
$id = $_GET['idPrinter'];
$pembeli = $data['idPembeli'];
$produk = $data['idPrinter'];
$jml = $data['jumlah'];
$insert = mysqli_query($db, "INSERT INTO transaksi (idPembeli, idProduk, jumlah, status) VALUES ('$pembeli', '$produk', '$jml', 'bd')");
return mysqli_affected_rows($db);
}
function edit($data){
global $db;
$id = $_GET['id'];
$printer = mysqli_real_escape_string($db, $data['printer']);
$spesifikasi = mysqli_real_escape_string($db,$data['spesifikasi']);
$harga = $data['harga'];
$update = mysqli_query($db, "UPDATE printer SET namaPrinter = '$printer', spesifikasi = '$spesifikasi', harga = '$harga' WHERE idPrinter = '$id'");
return mysqli_affected_rows($db);
}
function tambah($data){
global $db;
$printer = mysqli_real_escape_string($db, $data['printer']);
$spesifikasi = mysqli_real_escape_string($db,$data['spesifikasi']);
$harga = $data['harga'];
$insert = mysqli_query($db, "INSERT INTO printer(namaPrinter, spesifikasi, harga) VALUES('$printer', '$spesifikasi', '$harga')");
return mysqli_affected_rows($db);
}
?>
login.php
<?php
session_start();
require 'koneksi.php';
if (isset($_POST['login'])) {
$username = strtolower(mysqli_real_escape_string($db, $_POST['username']));
$password = strtolower(mysqli_real_escape_string($db, $_POST['password']));
$sql = mysqli_query($db, "SELECT * FROM akun WHERE username = '$username'");
if (mysqli_num_rows($sql)===1) {
$cek = mysqli_fetch_assoc($sql);
if ($password == $cek['password']) {
if ($cek ['role']== 'user') {
$_SESSION['login']= "$username";
echo "<script>alert('Login Berhasil !!!');
document.location.href = 'index.php';
</script>";
exit;
}if ($cek ['role'] == 'admin') {
$_SESSION['login'] = "$username";
echo "<script>alert('Login Berhasil !!!');
document.location.href = 'admin.php';
</script>";
exit;
}
}
}
$error = true;
}
?>
<!DOCTYPE html>
<html>
<head>
<meta charset="utf-8">
<meta name="viewport" content="width=device-width, initial-scale=1">
<title>Login</title>
<link rel="stylesheet" type="text/css" href="css/login.css">
</head>
<body>
<div class="kotak">
<h2 class="login">LOGIN</h2>
<form action="" method="post">
<input type="text" name="username" placeholder="username..." required>
<input type="password" name="password" placeholder="password..." required>
<?php if (isset($error)) {?>
<p>username/password salah</p>
<?php } ?>
<button type="submit" name="login">Login</button>
</form>
</div>
</body>
</html>
logout.php
<?php
session_start();
session_destroy();
echo "<script>alert('Logout berhasil');
document.location.href = 'index.php';
</script>";
?>
login.css
body{
font-family: sans-serif;
text-align: center;
color: aliceblue;
}
.kotak{
width: 250px;
height: 250px;
background: #1E88E5;
margin: 100px auto;
padding: 30px;
border-radius: 8px ;
box-shadow: 4px 5px grey;
}
.kotak input{
width: 100%;
box-sizing: border-box;
margin-top: 15px;
font-size: 11pt;
padding: 8px;
border-radius: 12px;
border: none;
background: #BBDEFB;
}
.kotak button{
margin-top: 30px;
width: 130px;
font-size: 12pt;
padding: 8px;
border-radius: 15px;
border: none;
background: aliceblue;
}
index.php
<?php
session_start();
require 'koneksi.php';
$select = mysqli_query($db, "SELECT * FROM printer");
$no = 1;
?>
<!DOCTYPE html>
<html>
<head>
<meta charset="utf-8">
<meta name="viewport" content="width=device-width, initial-scale=1">
<title></title>
<link rel="stylesheet" type="text/css" href="css/index.css">
</head>
<body>
<nav>
<h3>E-commerce Printer</h3>
<ul>
<li><?php if (!isset($_SESSION['login'])) { ?>
<a href="login.php">Login</a></li>
<?php }else{?>
<li><a href="logout.php"><?= $_SESSION['login'];?></a></li>
<li>|</li>
<li><a href="data.php">Data Transaksi</a></li>
<?php } ?>
</ul>
</nav>
<div class="kotak">
<h3>Menyediakan Printer berkualitas</h3>
<center>
<table >
<tr>
<th>No.</th>
<th>Nama Printer</th>
<th>Spesifikasi Printer</th>
<th>Harga</th>
<th>Aksi</th>
</tr>
<?php foreach ($select as $row) {?>
<tr>
<td><?php echo $no++;?></td>
<td><?= $row['namaPrinter']; ?></td>
<td><?= $row['spesifikasi']; ?></td>
<td><?= $row['harga']; ?></td>
<td><a href="beli.php?idPrinter=<?= $row['idPrinter'];?>">Beli</a></td>
</tr>
<?php } ?>
</table>
</center>
</div>
</body>
</html>
index.css
*{
margin: 0;
padding: 0;
}
body{
font-family: sans-serif;
background: aliceblue;
}
nav{
background: #1E88E5;
color: aliceblue;
justify-content: space-between;
display: flex;
padding: 20px 50px;
}
ul{
display: flex;
justify-content: center;
list-style: none;
}
li{
margin-right: 15px;
font-weight: 450;
}
nav a{
color: aliceblue;
text-decoration: none;
}
.kotak h3{
text-align: center;
margin-top: 65px;
margin-bottom: 10px;
text-transform: uppercase;
font-size: 20pt;
}
.kotak th{
padding: 8px 20px;
border: none;
border-right: 2px solid black;
border-top: 2px solid black;
border-bottom: 2px solid black;
border-left: 2px solid black;
}
.kotak td{
text-align: center;
padding: 12px 20px;
border: none;
border-right: 2px solid black;
border-top: 2px solid black;
border-bottom: 2px solid black;
border-left: 2px solid black;
}
.kotak a{
background: #1E88E5;
text-decoration: none;
color: aliceblue;
padding: 7px;
border-radius: 5px;
}
beli.php
<?php
session_start();
require 'koneksi.php';
if (!isset($_SESSION['login'])) {
echo "<script>alert('Login dulu masbro');
document.location.href = 'login.php';
</script>";
}
$id = $_GET['idPrinter'];
$session = $_SESSION['login'];
$select = mysqli_query($db, "SELECT * FROM akun WHERE username='$session'");
$baris = mysqli_fetch_assoc($select);
$hasil = mysqli_query($db, "SELECT * FROM printer WHERE idPrinter = '$id'");
$row = mysqli_fetch_assoc($hasil);
if (isset($_POST['beli'])) {
if (beli($_POST) > 0) {
echo "<script>alert('Pembelian berhasil');
document.location.href = 'index.php';
</script>";
}
}
?>
<!DOCTYPE html>
<html>
<head>
<meta charset="utf-8">
<meta name="viewport" content="width=device-width, initial-scale=1">
<title>Pembelian</title>
<link rel="stylesheet" type="text/css" href="css/beli.css">
</head>
<body>
<nav>
<h2>E-commerce Printer</h2>
<ul>
<li><a href="logout.php"><?= $_SESSION['login'];?></a></li>
<li>|</li>
<li><a href="index.php">Halaman Utama</a></li>
</ul>
</nav>
<div class="kotak">
<h2>Form Pembelian</h2>
<form action="" method="POST">
<input type="number" name="idPrinter" value="<?= $row['idPrinter']?>" readonly hidden>
<input type="number" name="idPembeli" value="<?= $baris['idUser']?>" readonly hidden>
<label for="pembeli">Pembeli</label>
<input type="text" name="pembeli" value="<?= $_SESSION['login']?>" readonly>
<label for="printer">Nama Printer</label>
<input type="text" name="printer" value="<?= $row['namaPrinter']?>" readonly>
<label for="spesifikasi">Spesifikasi Printer</label>
<input type="textarea" name="spesifikasi" value="<?= $row['spesifikasi']?>" readonly>
<label for="harga">Harga</label>
<input type="number" name="harga" value="<?= $row['harga']?>" readonly>
<label for="jumlah">Jumlah Pembelian</label>
<input type="number" name="jumlah" min="1" required>
<center><button type="submit" name="beli">Beli Sekarang</button></center>
</form>
</div>
</body>
</html>
beli.css
*{
margin: 0;
padding: 0;
}
body{
font-family: sans-serif;
background: aliceblue;
}
nav{
background: #1E88E5;
color: aliceblue;
justify-content: space-between;
display: flex;
padding: 20px 50px;
}
ul{
display: flex;
justify-content: center;
list-style: none;
}
li{
margin-right: 15px;
font-weight: 450;
}
nav a{
color: aliceblue;
text-decoration: none;
}
.kotak{
width: 300px;
height: 470px;
background: #1E88E5;
margin: 100px auto;
padding: 30px;
border-radius: 8px ;
box-shadow: 4px 5px grey;
}
.kotak h2{
text-align: center;
color: aliceblue;
margin-top: 20px;
margin-bottom: 30px;
}
.kotak label{
color: aliceblue;
}
.kotak input{
width: 100%;
margin-bottom: 13px;
box-sizing: border-box;
font-size: 11pt;
padding: 8px;
border-radius: 7px;
border: none;
background: #BBDEFB;
}
.kotak button{
margin-top: 20px;
width: 130px;
font-size: 12pt;
padding: 8px;
border-radius: 15px;
border: none;
background: aliceblue;
}
data.php
<?php
session_start();
require 'koneksi.php';
$session = $_SESSION['login'];
if (!isset($_SESSION['login'])) {
echo "<script>alert('Login dulu masbro');
document.location.href = 'login.php';
</script>";
}
$sql = mysqli_query($db, "SELECT * FROM transaksi INNER JOIN printer ON printer.idPrinter = transaksi.idProduk INNER JOIN akun ON akun.idUser = transaksi.idPembeli WHERE akun.username = '$session'");
$no = 1;
?>
<!DOCTYPE html>
<html>
<head>
<meta charset="utf-8">
<meta name="viewport" content="width=device-width, initial-scale=1">
<title>Data Transaksi</title>
<link rel="stylesheet" type="text/css" href="css/data.css">
</head>
<body>
<nav>
<h3>E-commerce Printer</h3>
<ul>
<li><a href="logout.php"><?= $_SESSION['login'];?></a></li>
<li>|</li>
<li><a href="index.php">Halaman Utama</a></li>
</ul>
</nav>
<div class="kotak">
<h2>Data Pembelian</h2>
<center>
<table>
<tr>
<th>No</th>
<th>Nama Printer</th>
<th>Spesifikasi Printer</th>
<th>Harga</th>
<th>Jumlah</th>
<th>Status</th>
</tr>
<?php foreach ($sql as $row) {?>
<tr>
<td><?php echo $no++; ?></td>
<td><?= $row['namaPrinter'] ?></td>
<td><?= $row['spesifikasi'] ?></td>
<td><?= $row['harga'] ?></td>
<td><?= $row['jumlah'] ?></td>
<td><?php if ($row['status']=='bd') {?>
<a href="hapuspesanan.php?id=<?= $row ['idTransaksi'];?>">Batalkan pesanan</a>
<?php }elseif($row['status']=='sd'){ ?>
<p>Pesanan sudah dikonfirmasi</p>
<?php }elseif($row['status']=='r'){ ?>
<p>Pesanan ditolak</p>
</td>
</tr>
<?php } }?>
</table>
</center>
</div>
</body>
</html>
data.css
*{
margin: 0;
padding: 0;
}
body{
font-family: sans-serif;
background: aliceblue;
}
nav{
background: #1E88E5;
color: aliceblue;
justify-content: space-between;
display: flex;
padding: 20px 50px;
}
ul{
display: flex;
justify-content: center;
list-style: none;
}
li{
margin-right: 15px;
font-weight: 450;
}
nav a{
color: aliceblue;
text-decoration: none;
}
.kotak h2{
text-align: center;
margin-top: 65px;
margin-bottom: 10px;
text-transform: uppercase;
font-size: 20pt;
}
.kotak th{
padding: 8px 20px;
border: none;
border-right: 2px solid black;
border-top: 2px solid black;
border-bottom: 2px solid black;
border-left: 2px solid black;
}
.kotak td{
text-align: center;
padding: 12px 20px;
border: none;
border-right: 2px solid black;
border-top: 2px solid black;
border-bottom: 2px solid black;
border-left: 2px solid black;
}
.kotak a{
background: #1E88E5;
text-decoration: none;
color: aliceblue;
padding: 7px;
border-radius: 5px;
}
hapuspesanan.php
<?php
session_start();
require 'koneksi.php';
$session = $_SESSION['login'];
$sql = mysqli_query($db, "SELECT * FROM akun WHERE username = '$session'");
$cek = mysqli_fetch_assoc($sql);
$id = $_GET['id'];
$delete = mysqli_query($db, "DELETE FROM transaksi WHERE idTransaksi = '$id'");
echo "<script>alert('Pesanan telah dihapus');
document.location.href = 'data.php';
</script>";
?>
admin.php
<?php
session_start();
require 'koneksi.php';
if (!isset($_SESSION['login'])) {
echo "<script>alert('Login dulu masbro');
document.location.href = 'login.php';
</script>";
}
$session = $_SESSION['login'];
$sql = mysqli_query($db, "SELECT * FROM akun WHERE username='$session'");
$cek = mysqli_fetch_assoc($sql);
if ($cek['role']=='user') {
echo "<script>alert('User tidak bisa memasuki halaman admin');
document.location.href = 'index.php';
</script>";
}
$printer = mysqli_query($db, "SELECT * FROM printer");
$transaksi = mysqli_query($db, "SELECT * FROM transaksi INNER JOIN printer ON printer.idPrinter = transaksi.idProduk INNER JOIN akun ON akun.idUser = transaksi.idPembeli");
$no = 1;
?>
<!DOCTYPE html>
<html>
<head>
<meta charset="utf-8">
<meta name="viewport" content="width=device-width, initial-scale=1">
<title>Admin</title>
<link rel="stylesheet" type="text/css" href="css/admin.css">
</head>
<body>
<nav>
<h2>E-commerce Printer</h2>
<ul>
<li>
<a href="logout.php"><?= $_SESSION['login']; ?></a>
</li>
</ul>
</nav>
<div class="kotak">
<h2>Data Produk</h2>
<center>
<table>
<tr>
<th>No.</th>
<th>Nama Printer</th>
<th>Spesifikasi Printer</th>
<th>Harga</th>
<th>Aksi</th>
</tr>
<?php foreach ($printer as $row) {?>
<tr>
<td><?php echo $no++;?></td>
<td><?= $row['namaPrinter']; ?></td>
<td><?= $row['spesifikasi']; ?></td>
<td><?= $row['harga']; ?></td>
<td><a href="editproduk.php?id=<?= $row['idPrinter'];?>" class="edit">Edit</a>
<a href="hapusproduk.php?id=<?= $row['idPrinter'];?>" class="hapus">Hapus</a>
</td>
</tr>
<?php } ?>
<tr>
<td colspan="5"><a href="tambahproduk.php">Tambah produk</a></td>
</tr>
</table>
</center>
<h2>Data Transaksi</h2>
<center>
<table>
<tr>
<th>No.</th>
<th>Pembeli</th>
<th>Nama Printer</th>
<th>Spesifikasi Printer</th>
<th>Harga</th>
<th>Jumlah</th>
<th>Status</th>
</tr>
<?php $no = 1;
foreach ($transaksi as $row) {
?>
<tr>
<td><?php echo $no++;?></td>
<td><?= $row['username']; ?></td>
<td><?= $row['namaPrinter']; ?></td>
<td><?= $row['spesifikasi']; ?></td>
<td>Rp. <?= $row['harga']; ?></td>
<td><?= $row['jumlah']; ?></td>
<td><?php if ($row['status']=='bd'){?>
<a href="confirm.php?id=<?= $row['idTransaksi'];?>">Konfirmasi</a>
<a href="reject.php?id=<?= $row['idTransaksi']?>" class="hapus">Reject pesanan</a>
<?php }elseif($row['status']=='sd'){ ?>
<p>Pesanan sudah dikonfirmasi</p>
<?php }elseif($row['status']=='r'){ ?>
<p>Pesanan ditolak</p>
<?php } ?>
</td>
</tr>
<?php } ?>
</table>
</center>
</div>
</body>
</html>
admin.css
*{
margin: 0;
padding: 0;
}
body{
font-family: sans-serif;
background: aliceblue;
}
nav{
background: #1E88E5;
color: aliceblue;
justify-content: space-between;
display: flex;
padding: 20px 50px;
}
ul{
display: flex;
justify-content: center;
list-style: none;
}
li{
margin-right: 15px;
font-weight: 450;
}
nav a{
color: aliceblue;
text-decoration: none;
}
.kotak h2{
text-align: center;
margin-top: 65px;
margin-bottom: 10px;
text-transform: uppercase;
font-size: 20pt;
}
.kotak th{
padding: 8px 20px;
border: none;
border-right: 2px solid black;
border-top: 2px solid black;
border-bottom: 2px solid black;
border-left: 2px solid black;
}
.kotak td{
text-align: center;
padding: 12px 20px;
border: none;
border-right: 2px solid black;
border-top: 2px solid black;
border-bottom: 2px solid black;
border-left: 2px solid black;
}
.kotak .edit{
background: yellow;
text-decoration: none;
color: black;
padding: 7px;
border-radius: 5px;
}
.kotak .hapus{
background: red;
text-decoration: none;
color: black;
padding: 7px;
border-radius: 5px;
}
.kotak a{
background: #1E88E5;
text-decoration: none;
color: aliceblue;
padding: 7px;
border-radius: 5px;
}
tambahproduk.php
<?php
session_start();
require 'koneksi.php';
if (isset($_POST['tambah'])) {
if (tambah($_POST)>0) {
echo "<script>alert('Produk berhasil ditambahkan');
document.location.href = 'admin.php';
</script>";
}
}
?>
<!DOCTYPE html>
<html>
<head>
<meta charset="utf-8">
<meta name="viewport" content="width=device-width, initial-scale=1">
<title>Tambah Produk</title>
<link rel="stylesheet" type="text/css" href="css/tambah.css">
</head>
<body>
<nav>
<h2>E-commerce Printer</h2>
<ul>
<li><a href="logout.php"><?= $_SESSION['login'];?></a></li>
<li>|</li>
<li><a href="admin.php">Halaman Utama</a></li>
</ul>
</nav>
<div class="kotak">
<h2>Tambah Produk</h2>
<form action="" method="POST">
<label for="printer">Nama Printer</label>
<input type="text" name="printer" required>
<label for="spesifikasi">Spesifikasi Printer</label>
<textarea name="spesifikasi" required></textarea>
<label for="harga">Harga</label>
<input type="number" name="harga" required>
<center><button type="submit" name="tambah">Tambah Produk</button></center>
</form>
</div>
</body>
</html>
tambah.css
*{
margin: 0;
padding: 0;
}
body{
font-family: sans-serif;
background: aliceblue;
}
nav{
background: #1E88E5;
color: aliceblue;
justify-content: space-between;
display: flex;
padding: 20px 50px;
}
ul{
display: flex;
justify-content: center;
list-style: none;
}
li{
margin-right: 15px;
font-weight: 450;
}
nav a{
color: aliceblue;
text-decoration: none;
}
.kotak{
width: 300px;
height: 390px;
background: #1E88E5;
margin: 100px auto;
padding: 30px;
border-radius: 8px ;
box-shadow: 4px 5px grey;
}
.kotak h2{
text-align: center;
color: aliceblue;
margin-top: 20px;
margin-bottom: 30px;
}
.kotak label{
color: aliceblue;
}
.kotak input{
width: 100%;
margin-bottom: 13px;
box-sizing: border-box;
font-size: 11pt;
padding: 8px;
border-radius: 7px;
border: none;
background: #BBDEFB;
}
.kotak textarea{
width: 100%;
height: 80px;
margin-bottom: 13px;
box-sizing: border-box;
font-size: 11pt;
padding: 8px;
border-radius: 7px;
border: none;
background: #BBDEFB;
}
.kotak button{
margin-top: 20px;
width: 130px;
font-size: 12pt;
padding: 8px;
border-radius: 15px;
border: none;
background: aliceblue;
}
editproduk.php
<?php
session_start();
require 'koneksi.php';
$id = $_GET['id'];
$sql = mysqli_query($db, "SELECT * FROM printer WHERE idPrinter = '$id'");
$cek = mysqli_fetch_assoc($sql);
if (isset($_POST['edit'])) {
if (edit($_POST)>0) {
echo "<script>alert('Produk berhasil diedit');
document.location.href = 'admin.php';
</script>";
}else{
header('location: admin.php');
}
}
?>
<!DOCTYPE html>
<html>
<head>
<meta charset="utf-8">
<meta name="viewport" content="width=device-width, initial-scale=1">
<title>Edit Produk</title>
<link rel="stylesheet" type="text/css" href="css/edit.css">
</head>
<body>
<nav>
<h2>E-commerce Printer</h2>
<ul>
<li><a href="logout.php"><?= $_SESSION['login'];?></a></li>
<li>|</li>
<li><a href="admin.php">Halaman Utama</a></li>
</ul>
</nav>
<div class="kotak">
<h2>Edit Produk</h2>
<form action="" method="POST">
<label for="printer">Nama Printer</label>
<input type="text" name="printer" value="<?= $cek['namaPrinter']?>" required>
<label for="spesifikasi">Spesifikasi Printer</label>
<textarea name="spesifikasi" required><?= $cek['spesifikasi']?></textarea>
<label for="harga">Harga</label>
<input type="number" name="harga" value="<?= $cek['harga']?>" required>
<center><button type="submit" name="edit">Edit</button></center>
</form>
</div>
</body>
</html>
edit.css
*{
margin: 0;
padding: 0;
}
body{
font-family: sans-serif;
background: aliceblue;
}
nav{
background: #1E88E5;
color: aliceblue;
justify-content: space-between;
display: flex;
padding: 20px 50px;
}
ul{
display: flex;
justify-content: center;
list-style: none;
}
li{
margin-right: 15px;
font-weight: 450;
}
nav a{
color: aliceblue;
text-decoration: none;
}
.kotak{
width: 300px;
height: 390px;
background: #1E88E5;
margin: 100px auto;
padding: 30px;
border-radius: 8px ;
box-shadow: 4px 5px grey;
}
.kotak h2{
text-align: center;
color: aliceblue;
margin-top: 20px;
margin-bottom: 30px;
}
.kotak label{
color: aliceblue;
}
.kotak input{
width: 100%;
margin-bottom: 13px;
box-sizing: border-box;
font-size: 11pt;
padding: 8px;
border-radius: 7px;
border: none;
background: #BBDEFB;
}
.kotak textarea{
width: 100%;
height: 80px;
margin-bottom: 13px;
box-sizing: border-box;
font-size: 11pt;
padding: 8px;
border-radius: 7px;
border: none;
background: #BBDEFB;
}
.kotak button{
margin-top: 20px;
width: 130px;
font-size: 12pt;
padding: 8px;
border-radius: 15px;
border: none;
background: aliceblue;
}
hapusproduk.php
<?php
require 'koneksi.php';
$id = $_GET['id'];
$delete = mysqli_query($db, "DELETE FROM printer WHERE idPrinter = '$id'");
echo "<script>alert('Produk sudah terhapus');
document.location.href = 'admin.php';
</script>";
?>
hapuspesanan.php
<?php
session_start();
require 'koneksi.php';
$session = $_SESSION['login'];
$sql = mysqli_query($db, "SELECT * FROM akun WHERE username = '$session'");
$cek = mysqli_fetch_assoc($sql);
$id = $_GET['id'];
$delete = mysqli_query($db, "DELETE FROM transaksi WHERE idTransaksi = '$id'");
echo "<script>alert('Pesanan telah dihapus');
document.location.href = 'data.php';
</script>";
?>
confirm.php
<?php
require 'koneksi.php';
$id = $_GET['id'];
$confirm = mysqli_query($db, "UPDATE transaksi SET status = 'sd' WHERE idTransaksi = '$id'");
echo "<script>alert('Konfirmasi berhasil');
document.location.href = 'admin.php';
</script>";
?>
rejectpesanan.php
<?php
require 'koneksi.php';
$id = $_GET['id'];
$confirm = mysqli_query($db, "UPDATE transaksi SET status = 'r' WHERE idTransaksi = '$id'");
echo "<script>alert('Pesanan berhasil direject');
document.location.href = 'admin.php';
</script>";
?>
struktur databasenya
idPembeli dan idProduk dijadikan foreign key agar bisa direlasikan
Gokill bang
BalasHapus