Anda di halaman 1dari 27

DOKUMENTASI

TUGAS CRUD

Disusun Oleh :

Nama : William Prasetyo Utomo


Kelas : XI-B
Kompetensi Keahlian : RPL

SMK TELEKOMUNIKASI TUNAS HARAPAN


KABUPATEN SEMARANG
2023
Apa itu CRUD?

CRUD adalah singkatan dari Create, Read, Update, dan Delete. Keempat hal tersebut
merupakan perintah dengan peran yang esensial dalam sebuah aplikasi database yang sifatnya
relational.

Beberapa contoh DBMS(Database Management System) yang menggunakan CRUD sebagai


fungsi utamanya yaitu Oracle Database, Microsoft SQL Server, MySQL, PostgreSQL, dan
sebagainya.

Fungsi CRUD
Seperti namanya, keempat fungsi ini merupakan fondasi kerja sebuah database. Bayangkan
saja kinerja sebuah database itu sebagai sebuah perpustakaan. Agar operasional perpustakaan
dapat berjalan, kamu perlu sebuah sistem pendataan buku-buku yang ada di dalamnya.

Dengan analogi tersebut, berikut adalah penjelasan tentang fungsi-fungsi dalam CRUD:

A. Create
Fungsi Create berguna untuk membuat entri atau record baru dalam sebuah tabel di dalam
database. Di dalam aplikasi berbasis SQL, fungsi create seringkali disebut dengan insert.

Jika dianalogikan dengan skenario di atas, fungsi create ini akan digunakan ketika kamu
menambahkan buku baru ke dalam katalog perpustakaan. Buku tersebut akan ditandai dengan
identitas khusus agar lebih mudah untuk diakses di kemudian hari.

B. Read
Fungsi read ini berguna untuk membaca entri data yang sudah terdaftar dalam sebuah
database. Namun, fungsi ini tidak akan memberikan akses untuk mengubah data yang telah
tersimpan di dalam database.

Dalam sebuah perpustakaan, tentunya ada sebuah sistem yang akan memberitahukan letak
sebuah buku dan apa isi dari buku tersebut. Nah, sistem inilah yang menjadi padanan dari
fungsi read dalam konsep CRUD.

C. Update
Fungsi update ini berperan penting untuk memperbarui entri data ketika informasi di
dalamnya memerlukan perubahan. Dengan fungsi ini, kamu dapat mengubah detail dari
sebuah entri di database.

Bayangkan saja fungsi ini ketika kamu ingin mengganti buku yang ada di perpustakaan kamu
dengan cetakan terbaru atau menukarnya dengan judul lain. Fungsi ini tentunya sangat
diperlukan untuk menciptakan database yang dinamis dan progresif.
D. Delete
Seperti namanya, fungsi delete ini berguna untuk menghapus entri data yang sudah tidak
diperlukan dalam sebuah database. Ketika menggunakan fungsi ini, kamu akan mengakses
detail terkait sebuah entri dan kemudian memberikan perintah kepada sistem untuk
menghilangkannya dari database.

Hasil Pengerjaan Tugas CRUD

A. config.php
<?php

$server = "localhost";
$user = "root";
$password = "";
$nama_database = "space_gaming_house";

$db = mysqli_connect($server, $user, $password, $nama_database);

if( !$db ){
    die("Gagal terhubung dengan database: " . mysqli_connect_error());
}

?>

B. indeks.php
<!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">
    <title>Homepage</title>
    <style>
        @import url('https://fonts.googleapis.com/css2?
family=Orbitron&display=swap');
        body {
            background-color: #000000;
            margin: 0;
            padding: 0;
        }

        .container {
            font-family : 'Orbitron' , sans-serif;
            font-style : normal;
            font-weight : 400;
            font-display : swap;
            width: 1000px;
            margin: 0 auto;
            padding: 20px;
            background-color: #000080;
            box-shadow: 0px 4px 10px rgba(128, 0, 128);
        }

        h1 {
            text-align: center;
            color: #C0C0C0;
        }

        ul {
            list-style-type: none;
            padding: 0;
        }

        li {
            margin-bottom: 10px;
        }

        a {
            color: #C0C0C0;
            text-decoration: none;
        }

        a:hover {
            text-decoration: underline;
        }
    </style>
</head>
<body>
    <div class="container">
    <h1>SPACEGAMING HOUSE</h1>
    <br>
        <!-- cek apakah sudah login -->
    <?php
    session_start();
    if($_SESSION['status']!="login"){
        header("location:login.php?pesan=belum_login");
    }
    ?>
 
    <h4>Welcome, <?php echo $_SESSION['username']; ?> Silahkan pilih.</h4>
 
    <br/>
    <br/>
 
    <a href="logout.php">LOGOUT</a>
    <ul>
        <li><a href="master-pc&gear.php"> PC & Gear</a></li>
        <li><a href="penjualan.php"> History </a></li>
    </ul>
    </div>
</body>
</html>

C. master-pc&gear.php
<?php
include("config.php"); ?>

<!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">
    <title>List Computer</title>
    <style>
        @import url('https://fonts.googleapis.com/css2?
family=Orbitron&display=swap');
        body {
            font-family: Arial, sans-serif;
            background-color: #111;
            color: #fff;
            margin: 0;
            padding: 0px;
        }

        .container {
            font-family: 'Orbitron';
            width: 1000px;
            margin: 0 auto;
            padding: 100px;
            background-color: #222;
            box-shadow: 0 0 10px rgba(0, 0, 0, 0.5);
        }

        h1 {
            text-align: center;
            color: #fff;
            margin-bottom: 20px;
            text-transform: uppercase;
        }

        table {
            width: 100%;
            border-collapse: collapse;
            margin-top: 20px;
        }

        th, td {
            padding: 10px;
            text-align: left;
            border-bottom: 1px solid #333;
        }

        th {
            background-color: #333;
        }

        tr:hover {
            background-color: #555;
        }
    </style>
</head>
<body>
    <div class="container">
    <h1>List PC&Gear</h1>
    <nav>
        <a href="index.php">Home</a>
        <br>
        <br>
        <form action="master-pc&gear.php" method="get">
            <label>Search :</label>
            <input type="text" name="Search">
            <input type="submit" value="Search">
        </form>
    </nav>
    <br>
    <nav>
        <a href="form-tambah-pc.php">[+] Tambah Baru</a>
    </nav>
    <br>
        <?php //fungsi cari
        if(isset($_GET['Search'])){
            $Search = $_GET['Search'];
            echo "<b>Hasil pencarian : ".$Search."</b>";
        }
        ?>
    <table border = "1">    
    <tr>
        <th>Nomor PC</th>
        <th>Nama_PC</th>
        <th>Kategori</th>
        <th>Gear</th>
        <th>Price PC&Gear</th>
        <th>Price PC</th>
        <th>Price Gear
        <th>Deskripsi</th>
    </tr>
    <?php
       
        //mesin pencari
        if(isset($_GET['Search'])){
            $Search = $_GET['Search'];
            $sql = "SELECT * FROM master_pc_gear WHERE Nomor_PC like '%".
$Search."%'";
        }else{
            $sql = "SELECT * FROM master_pc_gear";
        }
       
       // $sql = "SELECT * FROM tabel_barang";
        $query = mysqli_query($db, $sql);

        while($barang = mysqli_fetch_array($query)){
           echo "<tr>";
           
           echo "<td>".$barang['Nomor_PC']."</td>";
           echo "<td>".$barang['Nama_PC']."</td>";
           echo "<td>".$barang['Kategori']."</td>";
           echo "<td>".$barang['Gear']."</td>";
           echo "<td>".$barang['Price_PC_Gear']."</td>";
           echo "<td>".$barang['Price_PC']."</td>";
           echo "<td>".$barang['Price_Gear']."</td>";
           echo "<td>".$barang['Deskripsi']."</td>";
           
       
           echo "<td>";
           echo "<a href='form-edit-pc&gear.php?id=".
$barang['Nomor_PC']."'>Edit</a>";
           echo "<a href='hapus-pc&gear.php?id=".
$barang['Nomor_PC']."'>Hapus</a>";
           echo "</td>";

           echo "</tr>";
        }
    ?>
    </table>
    <p>Total: <?php echo mysqli_num_rows($query) ?></p>
    </div>
</body>
</html>

D. penjualan_pc&gear.php
<?php include("config.php"); ?>

<!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">
    <title>List Penjualan PC</title>
</head>
<style>
        @import url('https://fonts.googleapis.com/css2?
family=Orbitron&display=swap');
        body {
            font-family: 'Orbitron', sans-serif;
            background-color: #111;
            color: #fff;
            margin: 0;
            padding: 0px;
        }

        .container {
            font-family: 'Orbitron';
            width: 1000px;
            margin: 0 auto;
            padding: 100px;
            background-color: #222;
            box-shadow: 0 0 10px rgba(0, 0, 0, 0.5);
        }

        h1 {
            text-align: center;
            color: #fff;
            margin-bottom: 20px;
            text-transform: uppercase;
        }

        table {
            width: 100%;
            border-collapse: collapse;
            margin-top: 20px;
        }

        th, td {
            padding: 10px;
            text-align: left;
            border-bottom: 1px solid #333;
        }

        th {
            background-color: #333;
        }

        tr:hover {
            background-color: #555;
        }
    </style>
<body>
    </div>
    <h1>List Penjualan PC</h1>
    <nav>
        <a href="index.php">Home</a>
        <br>
        <br>
        <form action="master-pc&gear.php" method="get">
            <label>Search :</label>
            <input type="text" name="Search">
            <input type="submit" value="Search">
        </form>
    </nav>
    <br>
    <h2>Barang yang Tersedia</h2>
    <br>
        <?php //fungsi cari
        if(isset($_GET['Search'])){
            $Search = $_GET['Search'];
            echo "<b>Hasil pencarian : ".$Search."</b>";
        }
        ?>
    <table border = "1">
    <tr>
        <th>Nomor PC</th>
        <th>Nama PC</th>
        <th>Kategori</th>
        <th>Gear</th>
        <th>Price PC&Gear</th>
        <th>Price PC</th>
        <th>Price Gear</th>
        <th>Deskripsi</th>
    </tr>
    <?php
       
        //mesin pencari
        if(isset($_GET['Search'])){
            $Search = $_GET['Search'];
            $sql = "SELECT * FROM master_pc_gear WHERE Nomor_PC like '%".
$Search."%'";
        }else{
            $sql = "SELECT * FROM master_pc_gear";
        }
       
       // $sql = "SELECT * FROM tabel_barang";
        $query = mysqli_query($db, $sql);

        while($barang = mysqli_fetch_array($query)){
           echo "<tr>";
           
           echo "<td>".$barang['Nomor_PC']."</td>";
           echo "<td>".$barang['Nama_PC']."</td>";
           echo "<td>".$barang['Kategori']."</td>";
           echo "<td>".$barang['Gear']."</td>";
           echo "<td>".$barang['Price_PC_Gear']."</td>";
           echo "<td>".$barang['Price_PC']."</td>";
           echo "<td>".$barang['Price_Gear']."</td>";
           echo "<td>".$barang['Deskripsi']."</td>";

           echo "</tr>";
        }
    ?>
    </table>
    <p>Total Barang: <?php echo mysqli_num_rows($query) ?></p>

    <br>
    <br>
    <h2>Tabel Client</h2>
    <br>
    <nav>
        <a href="form-penjualan-1.php">[+] Tambah Baru</a>
    </nav>
    <br>
    <table border = "1">
    <tr>
        <th>Tanggal</th>
        <th>Nomor_PC </th>
        <th>Client Name </th>
        <th>Nama PC </th>
        <th>Gear</th>
        <th>Price_PC</th>
        <th>Price_Gear</th>
        <th>Price_PC_Gear</th>
        <th>Jumlah </th>
        <th>Harga Total </th>
    </tr>
    <?php
        $sql = "SELECT * FROM penjualan";
        $query = mysqli_query($db, $sql);

        while($barang = mysqli_fetch_array($query)){
           echo "<tr>";
           
           echo "<td>".$barang['tanggal']."</td>";
           echo "<td>".$barang['no_pc']."</td>";
           echo "<td>".$barang['client_name']."</td>";
           echo "<td>".$barang['Nama_PC']."</td>";
           echo "<td>".$barang['Gear']."</td>";
           echo "<td>".$barang['Price_PC']."</td>";
           echo "<td>".$barang['Price_Gear']."</td>";
           echo "<td>".$barang['Price_PC_Gear']."</td>";    
           echo "<td>".$barang['jumlah']."</td>";
           echo "<td>".$barang['harga_total']."</td>";

           echo "</tr>";
        }
    ?>
    </table>
    <p>Total Transaksi: <?php echo mysqli_num_rows($query) ?></p>

</body>
</html>
E. form_tambah_PC.php

<!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">
    <title>Tambah Barang</title>
    <style>
        @import url('https://fonts.googleapis.com/css2?
family=Orbitron&display=swap');
        body {
            font-family: 'Orbitron', sans-serif;
            background-color: #111;
            color: #fff;
            margin: 0;
            padding: 0;
        }

        .container {
            width: 400px;
            margin: 0 auto;
            padding: 20px;
            background-color: #222;
            box-shadow: 0 0 10px rgba(0, 0, 0, 0.5);
        }

        h1 {
            text-align: center;
            color: #fff;
            margin-bottom: 20px;
            text-transform: uppercase;
        }

        label {
            display: block;
            margin-bottom: 5px;
            color: #fff;
        }

        input[type="text"],
        select {
            width: 100%;
            padding: 8px;
            margin-bottom: 15px;
            border: none;
            background-color: #333;
            color: #fff;
        }

        input[type="submit"] {
            width: 100%;
            padding: 10px;
            border: none;
            background-color: #555;
            color: #fff;
            cursor: pointer;
            text-transform: uppercase;
        }

        input[type="submit"]:hover {
            background-color: #0056b3;
        }
    </style>
</head>
<body>
    <div class="container">
    <h1>Form Tambah PC</h1>
    <a href="master-pc&gear.php"><- Kembali</a>
    <form action="proses-tambah-barang.php" method="POST">
        <fieldset>
            <p>
                <label for="Nomor_PC"> Nomor_PC :</label>
                <input type="text" name="Nomor_PC" />
            </p>
            <p>
                <label for="Nama_PC"> Nama_PC :</label>
                <input type="text" name="Nama_PC" />
            </p>
            <p>
                <label for="Kategori">Kategori :</label>
                <select name="Kategori" id="Kategori">
                    <option value="High Definition PC">High Definition
PC</option>
                    <option value="Average Definition PC">Average Definition
PC</option>
                    <option value="Standart Definition PC">Standart Definition
PC</option>
                </select>
            </p>
            <p>
                <label for="Gear">Gear :</label>
                <input type="text" name="Gear" />
            </p>

            <p>
                <label for="Price_PC_Gear"> Price PC&Gear :</label>
                <input type="number" name="Price_PC_Gear" />
            </p>
            <p>
                <label for="Price_PC"> Price PC :</label>
                <input type="number" name="Price_PC" />
            </p>
            <p>
                <label for="Price_Gear"> Price Gear :</label>
                <input type="number" name="Price_Gear" />
            </p>
            <p>
                <label for="Deskripsi"> Deskripsi :</label>
                <input type="text" name="Deskripsi" />
            </p>
            <p>
                <input type="submit" value="Tambah Barang" name="tambah"/>
            </p>
        </fieldset>
    </form>
    </div>
</body>
</html>
F. proses_tambah_pc&gear.php
<?php
include("config.php");

if(isset($_POST['tambah'])){
    $Nomor_PC = $_POST['Nomor_PC'];
    $Nama_PC = $_POST['Nama_PC'];
    $Kategori = $_POST['Kategori'];
    $Gear = $_POST['Gear'];
    $Price_PC_Gear = $_POST['Price_PC_Gear'];
    $Price_PC = $_POST['Price_PC'];
    $Price_Gear = $_POST['Price_Gear'];
    $Deskripsi = $_POST['Deskripsi'];

    $sql = "INSERT INTO master_pc_gear(Nomor_PC, Nama_PC, Kategori, Gear,


Price_PC_Gear, Price_PC, Price_Gear, Deskripsi) VALUE ('$Nomor_PC''$Nama_PC',
'$Kategori','$Gear', '$Price_PC_Gear', '$Price_PC', '$Price_Gear',
'$Deskripsi')";
    $query = mysqli_query($db, $sql);

    if ($query){
        header('Location: master-pc&gear.php?status=sukses');
    }else{
        header('Location: master-pc&gear.php?status=gagal');

    }
}else {
    die("Akses dilarang...");
}

?>
G. form-edit-pc&gear.php
<?php
include("config.php");

if(!isset($_GET['id'])){
    header('Location: master-pc&gear.php');
}
    $Nomor_PC = $_GET['id'];
    $sql = "SELECT * FROM master_pc_gear WHERE Nomor_PC=$Nomor_PC";
    $query = mysqli_query($db, $sql);
    $barang = mysqli_fetch_assoc($query);
   
    if( mysqli_num_rows($query) < 1 ){
        die("data tidak ditemukan...");
    }
?>

<!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">
    <title>Form Edit Barang</title>
    <style>
        @import url('https://fonts.googleapis.com/css2?
family=Orbitron&display=swap');
        body {
            font-family: 'Orbitron', sans-serif;
            background-color: #111;
            color: #fff;
            margin: 0;
            padding: 0;
        }

        .container {
            width: 400px;
            margin: 0 auto;
            padding: 20px;
            background-color: #222;
            box-shadow: 0 0 10px rgba(0, 0, 0, 0.5);
        }

        h1 {
            text-align: center;
            color: #fff;
            margin-bottom: 20px;
            text-transform: uppercase;
        }

        label {
            display: block;
            margin-bottom: 5px;
            color: #fff;
        }

        input[type="text"],
        select {
            width: 100%;
            padding: 8px;
            margin-bottom: 15px;
            border: none;
            background-color: #333;
            color: #fff;
        }

        input[type="submit"] {
            width: 100%;
            padding: 10px;
            border: none;
            background-color: #555;
            color: #fff;
            cursor: pointer;
            text-transform: uppercase;
        }

        input[type="submit"]:hover {
            background-color: #0056b3;
        }
    </style>
</head>
<body>
    <div class="container">
    <h1>Form Edit Barang</h1>
    <a href="master-pc&gear.php"><- Kembali</a>
    <form action="proses-edit-pc&gear.php" method="POST">
        <fieldset>
        <input type="hidden" name="Nomor_PC" value="<?php echo
$barang['Nomor_PC'] ?>" />
            <p>
                <label for="Nomor_PC"> Nomor PC :</label>
                <input type="number" name="Nomor_PC" value="<?php echo
$barang['Nomor_PC'] ?>" />
            </p>
            <p>
                <label for="Nama_PC"> Nama PC</label>
                <input type="text" name="Nama_PC" value="<?php echo
$barang['Nama_PC'] ?>"/>
            </p>
            <p>
                <label for="Kategori"> Kategori :</label>
                <select name="Kategori" id="Kategori">
                    <option value="High Definition PC">High Definition
PC</option>
                    <option value="Average Defintition PC">Average Defintition
PC</option>
                    <option value="Standart Definition PC">Standart Definition
PC</option>
                </select>
            </p>
            <p>
                <label for="Gear"> Gear :</label>
                <input type="text" name="Gear" value="<?php echo $barang['Gear']
?>" />
            </p>
            <p>
                <label for="Price_PC_Gear"> Price PC & Gear :</label>
                <input type="number" name="Price_PC_Gear" value="<?php echo
$barang['Price_PC_Gear'] ?>" />
            </p>
            <p>
                <label for="Price_PC"> Price </label>
                <input type="number" name="Price_PC" value="<?php echo
$barang['Price_PC'] ?>" />
            </p>
            <p>
                <label for="Price_Gear"> Price Gear </label>
                <input type="number" name="Price_Gear" value="<?php echo
$barang['Price_Gear'] ?>" />
            </p>
            <p>
                <label for="Deskripsi"> Deskripsi :</label>
                <input type="text" name="Deskripsi" value="<?php echo
$barang['Deskripsi'] ?>"/>
            </p>
            <p>
                <input type="submit" value="SIMPAN" name="simpan"/>
            </p>
        </fieldset>
    </form>
    </div>
</body>
</html
H. proses-edit-pc&gear.php
<?php
include("config.php");

if(isset($_POST['simpan'])){
    $Nomor_PC = $_POST['Nomor_PC'];
    $Nama_PC = $_POST['Nama_PC'];
    $Kategori = $_POST['Kategori'];
    $Gear = $_POST['Gear'];
    $Price_PC_Gear = $_POST['Price_PC_Gear'];
    $Price_PC = $_POST['Price_PC'];
    $Price_Gear = $_POST['Price_Gear'];
    $Deskripsi = $_POST['Deskripsi'];
 

    $sql = "UPDATE master_pc_gear SET Nomor_PC='Nomor_PC', Nama_PC='$Nama_PC',


Kategori='$Kategori', Gear='$Gear', Price_PC_Gear='$Price_PC_Gear',
Price_PC='$Price_PC', Price_Gear='$Price_Gear', Deskripsi='$Deskripsi', WHERE
Nomor_PC=$Nomor_PC";
    $query = mysqli_query($db, $sql);

    if ($query){
        header('Location: master-pc&gear.php');
    }else{
        die("Gagal mengupdate data..");

    }  
}else {
    die("Akses dilarang...");
}
?>
I. hapus-pc&gear.php
<?php
include("config.php");

if(isset($_GET['id'])){
    $Nomor_PC = $_GET['id'];
    $sql = "DELETE FROM master_pc_gear WHERE Nomor_PC = $Nomor_PC";
    $query = mysqli_query($db, $sql);
    if($query){
        header('Location: master-pc&gear.php');      
    }else{
        die("Gagal menghapus...");
    }
}else{
    die("Akses dilarang...");
}
?>

J. form_Transaksi_1.php
<?php include("config.php");

$sql = "SELECT * FROM master_pc_gear";


$data = mysqli_query($db, $sql);

?>
<!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">
    <title>SpaceGamingHouse</title>
</head>
<style>
        @import url('https://fonts.googleapis.com/css2?
family=Orbitron&display=swap');
        body {
            font-family: 'Orbitron', sans-serif;
            background-color: #111;
            color: #fff;
            margin: 0;
            padding: 0;
        }

        .container {
            width: 400px;
            margin: 0 auto;
            padding: 20px;
            background-color: #222;
            box-shadow: 0 0 10px rgba(0, 0, 0, 0.5);
        }

        h1 {
            text-align: center;
            color: #fff;
            margin-bottom: 20px;
            text-transform: uppercase;
        }

        label {
            display: block;
            margin-bottom: 5px;
            color: #fff;
        }

        input[type="text"],
        select {
            width: 100%;
            padding: 8px;
            margin-bottom: 15px;
            border: none;
            background-color: #333;
            color: #fff;
        }

        input[type="submit"] {
            width: 100%;
            padding: 10px;
            border: none;
            background-color: #555;
            color: #fff;
            cursor: pointer;
            text-transform: uppercase;
        }

        input[type="submit"]:hover {
            background-color: #0056b3;
        }
    </style>
<body>
    <div class="container">
    <h1>Computer</h1>
    <h3>Transaksi Computer</h3>
    <a href="penjualan.php"><- Kembali</a>
    <fieldset>
        <form action="form-Transaksi-2.php" method="post">
            <table>
                <tr>
                    <td>Tanggal Penjualan</td>
                    <td>: <input type="date" name="tanggal"></td>
                </tr>
                <tr>
                    <td>Nomor PC</td>
                    <td>: <input type="text" name="no_pc"></td>
                </tr>
                <tr>
                    <td>Nama PC</td>
                    <td>: <select name="barang">
                        <option disabled selected>----</option>
                        <?php
                        while ($barang = mysqli_fetch_array($data)) {
                            echo "<option value=".$barang['no_pc'].">".
$barang['Nama_PC']." - (Rp. ".$barang['Price_PC_Gear'].")</option>";
                        }
                        ?>
                    </select></td>
                </tr>
                <tr>
                    <td>Jumlah Barang</td>
                    <td>: <input type="number" name="jumlah"></td>
                </tr>
            </table>
            <button type="submit" name="lanjut">Lanjut</button>
        </form>
    </fieldset>
    </div>
</body>
</html>
K. form_mainan_2.php
<?php include("config.php");

if (!isset($_POST['lanjut'])) {
    header('location:penjualan.php');
}

$tanggal = $_POST['tanggal'];
$no_pc = $_POST['no_pc'];
$jumlah = $_POST['jumlah'];

$sql = "SELECT * FROM master_pc_gear WHERE no_pc=$no_pc";


$data = mysqli_query($db, $sql);
$Nama_PC = mysqli_fetch_assoc($data);
$harga_total = $jumlah * $Nama_PC['harga_jual'];

?>
<!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">
    <title>SpaceGamingHouse</title>
</head>
<style>
        @import url('https://fonts.googleapis.com/css2?
family=Orbitron&display=swap');
        body {
            font-family: 'Orbitron', sans-serif;
            background-color: #111;
            color: #fff;
            margin: 0;
            padding: 0;
        }

        .container {
            width: 400px;
            margin: 0 auto;
            padding: 20px;
            background-color: #222;
            box-shadow: 0 0 10px rgba(0, 0, 0, 0.5);
        }

        h1 {
            text-align: center;
            color: #fff;
            margin-bottom: 20px;
            text-transform: uppercase;
        }

        label {
            display: block;
            margin-bottom: 5px;
            color: #fff;
        }

        input[type="text"],
        select {
            width: 100%;
            padding: 8px;
            margin-bottom: 15px;
            border: none;
            background-color: #333;
            color: #fff;
        }

        input[type="submit"] {
            width: 100%;
            padding: 10px;
            border: none;
            background-color: #555;
            color: #fff;
            cursor: pointer;
            text-transform: uppercase;
        }

        input[type="submit"]:hover {
            background-color: #0056b3;
        }
    </style>
<body>
    <div class="container">
    <h1>Transaksi Computer</h1>
    <h3>Tambah Penjualan (Data Konsumen)</h3>
    <a href="form-Transaksi-1.php"><- Kembali</a>
    <fieldset>
        <form action="proses-tambah-penjualan.php" method="post">
            <input type="text" name="Nama_PC" value="<?php echo
$nama_pc['nama_pc']." - ".$nama_pc['Nama_PC']; ?>" hidden>
            <table>
                <tr>
                    <td>Tanggal</td>
                    <td>: <input type="date" name="tanggal" value=<?php echo
$tanggal; ?> readonly></td>
                </tr>
                <tr>
                    <td>No PC</td>
                    <td>: <input type="text" name="no_pc" value=<?php echo
$no_pc; ?> readonly></td>
                </tr>
                <tr>
                    <td>Client Name</td>
                    <td>: <input type="text" name="client_name"></td>
                </tr>
                <tr>
                    <td>Nama PC</td>
                    <td>: <input type="text" value=<?php echo
$nama_pc['Nama_PC']; ?> readonly></td>
                </tr>
                <tr>
                    <td>Harga Satuan</td>
                    <td>: <input type="number" name="satuan" value=<?php echo
$barang['harga_jual']; ?> readonly readonly></td>
                </tr>
                <tr>
                    <td>Jumlah</td>
                    <td>: <input type="number" name="jumlah" value=<?php echo
$jumlah; ?> readonly></td>
                </tr>
                <tr>
                    <td>Harga Total</td>
                    <td>: <input type=. number" name="harga_total" value=<?php
echo $harga_total; ?> readonly></td>
                </tr>
            </table>
            <button type="submit" name="simpan">Simpan</button>
        </form>
    </fieldset>
    </div>
</body>
</html>
L. proses_tambah_penjualan_mainan.php
<?php
include("config.php");

if(isset($_POST['simpan'])){
    $tanggal = $_POST['tanggal'];
    $no = $_POST['no_pc'];
    $client = $_POST['client_name'];
    $nama_pc = $_POST['Nama_PC'];
    $Gear = $_POST['Gear'];
    $Price_PC_Gear = $_POST['Price_PC_Gear'];
    $Price_PC = $_POST['Price_PC'];
    $Price_Gear = $_POST['Price_Gear'];
    $jumlah = $_POST['jumlah'];
    $total = $_POST['harga_total'];

    $sql = "INSERT INTO penjualan(tanggal, no_pc, client_name, Nama_PC, Gear,


Price_PC_Gear, Price_PC, Price_Gear, jumlah, harga_total) VALUE ('$tanggal',
'$no','$client', '$nama_pc', '$Gear','$Price_PC_Gear', '$Price_PC',
'$Price_Gear', '$jumlah', '$total')";
    $query = mysqli_query($db, $sql);

    if ($query){
        header('Location: penjualan_pc&gear.php?status=sukses');
    }else{
        header('Location: penjualan_pc&gear.php?status=gagal');

    }
}else {
    die("Akses dilarang...");
}

?>
M.Database monster_toys

N. Isi Table master_mainan


O.Isi Table penjualan

P. Isi Table user

Anda mungkin juga menyukai