Professional Documents
Culture Documents
<?php
require 'config.php';
?>
<!DOCTYPE html>
<html>
<head>
</head>
<body>
<div class="judul">
</div>
<br><br>
<tr>
<th>No.</th>
<th>Nama Produk</th>
<th>Harga</th>
<th>Qty</th>
<th colspan="2">Aksi</th>
</tr>
<?php $i = 1; ?>
<tr>
<td><?= $i;?></td>
</tr>
</table>
</body>
</html>
CONFIG
<?php
$server = "localhost";
$user = "root";
$password = "";
$db = "penjualan";
function query($query) {
global $conn;
$rows = [];
$rows [] = $row;
return $rows;
function tambah($data){
global $conn;
$nama = htmlspecialchars($data["nama"]);
$harga = htmlspecialchars($data["harga"]);
$qty = htmlspecialchars($data["qty"]);
$query = "INSERT INTO produk VALUES
('','$nama','$harga','$qty')";
mysqli_query($conn, $query);
return mysqli_affected_rows($conn);
function hapus($no){
global $conn;
return mysqli_affected_rows($conn);
function ubah($data){
global $conn;
$no = $data["no"];
$nama = htmlspecialchars($data["nama"]);
$harga = htmlspecialchars($data["harga"]);
$qty = htmlspecialchars($data["qty"]);
nama = '$nama',
harga = '$harga',
qty = '$qty'
WHERE no = $no
";
mysqli_query($conn, $query);
return mysqli_affected_rows($conn);
?>
TAMBAH
<!DOCTYPE html>
<html>
<head>
</head>
<body>
<fieldset>
<p>
</p>
<p>
</p>
<p>
</p>
<p>
</p>
</fieldset>
</form>
</body>
</html>
PROSES TAMBAH
<?php
require 'config.php';
//cek apakah tombol submit sudah ditekan atau belum
if (isset($_POST["submit"])){
//cek apakah data berhasil ditambahkan atau tidak
if ( tambah($_POST) > 0){
echo "
<script>
alert('Data Berhasil Ditambahkan');
document.location.href = 'index.php';
</script>
";
}else{
echo "
<script>
alert('Data Gagal Ditambahkan');
document.location.href = 'index.php';
</script>
";
}
}
?>
UBAH
<?php
require 'config.php';
$no = $_GET["no"];
if (isset($_POST["submit"])){
echo "
<script>
document.location.href = 'index.php';
</script>
";
}else{
echo "
<script>
document.location.href = 'index.php';
</script>
";
?>
<!DOCTYPE html>
<html>
<head>
</head>
<body>
<fieldset>
<p>
</p>
<p>
</p>
<p>
</p>
<p>
</p>
</fieldset>
</form>
</body>
</html>
HAPUS
<?php
require 'config.php';
$no = $_GET["no"];
echo "
<script>
document.location.href = 'index.php';
</script>
";
}else{
echo "
<script>
document.location.href = 'index.php';
</script>
";
?>
STYLE
body{
font-family: 'cambria';
color: #000;
.judul{
background: #87D1D8;
padding: 10px;
text-align: center;
.judul h1,h2,h3{
height: 15px;
a{
/*color: #fff;*/
padding: 5px;
text-decoration: none;
.table{
border-collapse: collapse;