DITONIUS ZEBUA - 191011450300 - UAS pEMOGRAMAN WEB 2

You might also like

Download as pdf or txt
Download as pdf or txt
You are on page 1of 18

Nama : Ditonius Zebua

Nim : 191011450300

Kelas : 06TPLK001

Uas : Pemograman Web 2

1. Pembuatan Aplikasi crud sederhana menggunakan php

Read
<html>
<head>
<title>Ditonius Zebua</title>
<style>
.table1 {
font-family: sans-serif;
color: #444;
border-collapse: collapse;
width: 50%;
border: 1px solid #f2f5f7;
}

.table1 tr th{
background: #35A9DB;
color: #fff;
font-weight: normal;
}

.table1, th, td {
padding: 8px 20px;
text-align: left;
}

.table1 tr:hover {
background-color: #f5f5f5;
}

.table1 tr:nth-child(even) {
background-color: #f2f2f2;
}
</style>
</head>
<body style="font-family:arial">
<center><h1>Zebua Showroom</h1>
<h2>Ditonius Zebua</h2>
<h2>06TPLK001</h2></center>
<hr /></center>
<hr />
<a href="create.php">Tambah Data</a><br /><br />
<b>Data Barang</b>
<table style="width:100%" class="table1">
<tr>
<th>No</th>
<th>Merk Mobil</th>
<th>Nama Mobil</th>
<th>Harga </th>
<th>Stok </th>
<th colspan=3><center>Opsi</center></th>
</tr>

<?php
include "conectting.php";
$no = 1;
$data = mysqli_query($konek,"select * from tb_barang");
while($r = mysqli_fetch_array($data)){
$id_barang = $r['id_barang'];
$nama_merk = $r['nama_merk'];
$nama_barang = $r['nama_barang'];
$harga_barang = $r['harga_barang'];
$stok_barang = $r['stok_barang'];
?>
<tr><td><?php echo $no++; ?></td>

<td><?php echo $nama_merk; ?></td>


<td><?php echo $nama_barang; ?></td>
<td><?php echo $harga_barang; ?></td>
<td><?php echo $stok_barang; ?></td>
<td align=right width=70px><a href="update.php?id=<?php echo
$id_barang;?>">Edit</a></td>
<td align=right width=70px><a href="delete.php?id=<?php echo
$id_barang;?>">Hapus</a></td>
</tr>
<?php
}
?>
</table>
</body>
</html>
Create
<html>
<head>
<title>Showroom</title>
</head>
<body style="font-family:arial">
<center><h1>Zebua Showroom</h1>
<h2>Ditonius Zebua</h2>
<h2>06TPLK001</h2></center>
<hr />
<b>Tambah Data Baru</b>
<br/><br/>

<form action="create.php" method="post" name="form1">


<table width="100%" border="0">
<tr>

<tr>
<td>Merk Mobil</td>
<td><input type="text" name="nama_merk" size="50" required></td>
</tr>
<tr>
<td>Nama Mobil</td>
<td><input type="text" name="nama_barang" size="50" required></td>
</tr>
<tr>
<td>Harga Unit</td>
<td><input type="text" name="harga_barang" size="50" required></td>
</tr>
<tr>
<td>Stok Unit</td>
<td><input type="text" name="stok_barang" size="50" required></td>
</tr>
<tr>
<td></td>
<td><input type="submit" name="Submit" value=" Submit"></td>
</tr>
</table>
</form>

<?php

// Check If form submitted, insert form data into users table.


if(isset($_POST['Submit'])) {

$nama_merk = $_POST['nama_merk'];
$nama_barang = $_POST['nama_barang'];
$harga_barang = $_POST['harga_barang'];
$stok_barang = $_POST['stok_barang'];

// include database connection file


include "conectting.php";

// Insert user data into table


$tambah_barang = "insert into tb_barang
values('','$nama_merk','$nama_barang','$harga_barang','$stok_barang')";
$kerjakan=mysqli_query($konek, $tambah_barang);
if($kerjakan)
{
// Show message when user added
echo "Barang berhasil ditambahkan. <a href='index.php'>Lihat Data Barang</a>";
}
else
{
echo "Gagal bro";
}
}
?>
</body>
</html>

Update
<?php
// include database connection file
include "conectting.php";

// Check if form is submitted for user update, then redirect to homepage after update
if(isset($_POST['update']))
{
$id = $_POST['id'];
$nama_merk=$_POST['nama_merk'];
$nama_barang=$_POST['nama_barang'];
$harga_barang=$_POST['harga_barang'];
$stok_barang=$_POST['stok_barang'];

// update user data


$result = mysqli_query($konek, "UPDATE tb_barang SET nama_merk
='$nama_merk'nama_barang='$nama_barang',harga_barang='$harga_barang',stok_bara
ng='$stok_barang' WHERE id_barang=$id");

// Redirect to homepage to display updated user in list


header("Location: index.php");
}
?>
<?php
// Display selected user data based on id
// Getting id from url
$id = $_GET['id'];

// Fetech user data based on id


$result = mysqli_query($konek, "SELECT * FROM tb_barang WHERE id_barang=$id");

while($r = mysqli_fetch_array($result))
{
$id_barang = $r['id_barang'];
$nama_merk = $r['nama_merk'];
$nama_barang = $r['nama_barang'];
$harga_barang = $r['harga_barang'];
$stok_barang = $r['stok_barang'];
}
?>

<html>
<head>
<title>Ditonius Zebua</title>
</head>
<body style="font-family:arial">
<center><h1>Zebua Showroom</h1>
<h2>Ditonius Zebua</h2>
<h2>06TPLK001</h2></center>
<hr />
<b>Edit Data Barang</b>
<br/><br/>
<form name="update_user" method="post" action="update.php">
<table border="0">
<tr>
<td>ID</td>
<td><input type="text" size="50" name="id_barang" value="<?php echo
$id_barang;?>"></td>
</tr>
<tr>
<td>Nama Merk</td>
<td><input type="text" size="50" name="nama_merk" value="<?php echo
$nama_merk;?>"></td>
</tr>
<tr>
<td>Nama Barang</td>
<td><input type="text" size="50" name="nama_barang" value="<?php echo
$nama_barang;?>"></td>
</tr>
<tr>
<td>Harga Barang</td>
<td><input type="text" size="50" name="harga_barang" value="<?php echo
$harga_barang;?>"></td>
</tr>
<tr>
<td>Stok Barang</td>
<td><input type="text" size="50" name="stok_barang" value="<?php echo
$stok_barang;?>"></td>
</tr>
<tr>
<td><input type="hidden" name="id" value=<?php echo $_GET['id'];?>></td>
<td><input type="submit" name="update" value="Update"></td>

</tr>
</table>
</form>
</body>
</html>

Delete
<?php
// include database connection file
include "conectting.php";

// Get id from URL to delete that user


$id = $_GET['id'];

// Delete user row from table based on given id


$result = mysqli_query($konek, "DELETE FROM tb_barang WHERE id_barang=$id");

// After delete redirect to Home, so that latest user list will be displayed.
header("Location: index.php");
?>

You might also like