Proyek sederhana .php
Membuat halaman jual beli online sederhana
Target:
1.Form Login Admin
2.Form Tambah,Edit,Hapus
3.Halaman Untuk User
Home.php
<p align='right'><a href='admin.php'>SILAHKAN MASUK </a> [[ADMIN ONLY]]</p>
<center><h2>DAFTAR BARANG <h2></center>
<table border="1" width="550" align="center" bgcolor=#000ff>
<tr>
<td align="center"width=50 height=20 align="center" width=50><b>Kode</b></td>
<td align="center" width=200><b>Nama Barang</b></td>
<td align='center' width=300><b>Deskripsi</b></td>
<td align='center' width=300><b>Harga</b></td>
</tr>
<?php
include "koneksi.php";
$qdata = mysql_query("select kode,nama,deskripsi, harga from data");
while($rdata = mysql_fetch_array($qdata))
{
$kode = $rdata["kode"];
$nama = $rdata["nama"];
$deskripsi = $rdata["deskripsi"];
$harga = $rdata["harga"];
echo "<tr>
<td align='center' >$kode</tad>
<td>$nama</td>
<td>$deskripsi</td>
<td>Rp. $harga</td>
</tr>";
}
?>
</table>
OUTPUT:
Admin.php
<?php
echo "<form method='post' action='form_barang.php' >";
echo "<table cellpadding='3' cellspacing='3' align='center' bgcolor=#fff0ff>
<caption><strong><h3>SILAHKAN MASUK</h3></strong></caption></br>
<tr>
<td>Username</td>
<td> <input type='text' name='username'></td>
</tr>
<tr>
<td>Password</td>
<td><input type='password' name='password'></td>
</tr>
<td></td><td><input type='submit' name='login' value='masuk'></td>
</tr>";
echo "</table></form>";
?>
Membuat halaman jual beli online sederhana
Target:
1.Form Login Admin
2.Form Tambah,Edit,Hapus
3.Halaman Untuk User
Home.php
<p align='right'><a href='admin.php'>SILAHKAN MASUK </a> [[ADMIN ONLY]]</p>
<center><h2>DAFTAR BARANG <h2></center>
<table border="1" width="550" align="center" bgcolor=#000ff>
<tr>
<td align="center"width=50 height=20 align="center" width=50><b>Kode</b></td>
<td align="center" width=200><b>Nama Barang</b></td>
<td align='center' width=300><b>Deskripsi</b></td>
<td align='center' width=300><b>Harga</b></td>
</tr>
<?php
include "koneksi.php";
$qdata = mysql_query("select kode,nama,deskripsi, harga from data");
while($rdata = mysql_fetch_array($qdata))
{
$kode = $rdata["kode"];
$nama = $rdata["nama"];
$deskripsi = $rdata["deskripsi"];
$harga = $rdata["harga"];
echo "<tr>
<td align='center' >$kode</tad>
<td>$nama</td>
<td>$deskripsi</td>
<td>Rp. $harga</td>
</tr>";
}
?>
</table>
OUTPUT:
Admin.php
<?php
echo "<form method='post' action='form_barang.php' >";
echo "<table cellpadding='3' cellspacing='3' align='center' bgcolor=#fff0ff>
<caption><strong><h3>SILAHKAN MASUK</h3></strong></caption></br>
<tr>
<td>Username</td>
<td> <input type='text' name='username'></td>
</tr>
<tr>
<td>Password</td>
<td><input type='password' name='password'></td>
</tr>
<td></td><td><input type='submit' name='login' value='masuk'></td>
</tr>";
echo "</table></form>";
?>
OUTPUT:
Form Barang.php
<?php
echo "<form action='simpan.php' method='post'>";
echo "<table cellpadding='3' cellspacing='3' align='center'>
<caption><strong><h3>Input Data Barang</h3></strong></caption></br>
<tr>
<td>Kode Barang</td>
<td> <input type='text' name='kode' size=8 ></td>
</tr>
<tr>
<td>Nama Barang</td>
<td><input type='text' name='nama'></td>
</tr>
<tr>
<td>Deskripsi</td>
<td><textarea name='deskripsi' cols=20 rows=2></textarea></td>
</tr>
<tr>
<td>Harga</td>
<td>Rp. <input type='text' name='harga'><td>
</tr>
<tr>
<td></td><td><input type='submit' name='simpan' value='TAMBAH'></td>
</tr>";
echo "</table></form>";
?>
OUTPUT:
Simpan.php
<?php
include "koneksi.php";
$kode = $_POST['kode'];
$nama = $_POST['nama'];
$deskripsi = $_POST['deskripsi'];
$harga = $_POST['harga'];
$insert = "INSERT INTO data (kode, nama, deskripsi, harga) VALUES('$kode','$nama','$deskripsi','$harga')";
$insert_query = mysql_query($insert);
if($insert_query){
echo "<script>alert('Insert data $kode berhasil..!!')</script>";
echo "<script >location.href='home.php';</script>";
}
else{
echo "<script>alert('Gagal insert $kode')</script>";
echo "<script >location.href='form_barang.php';</script>";
echo mysql_error();
}
?>
OUTPUT:
Setelah berhasil menambahkan data dari form data.php,kita akan langsung ditujukan ke halaman home.php lagi:
Edit.php
<?php
include “koneksi.php”;?>
<table border=”1″ width=”550″ align=”center”>
<tr><td height=20 align=”center” width=50><b>Kode</b></td>
<td align=”center” width=170><b>Nama Barang</b></td>
<td align=’center’ width=250><b>deskripsi</b></td>
<td align=’center’ width=80><b>Harga</b></td>
</tr>
<?php
if($kirim_edit==1)
{
$query3 = “update data set kode=’$kode’, nama=’$nama’, deskripsi=’$deskripsi’, harga=’$harga’
where kode=’$kodeg’”;
mysql_query($query3);
}
$i=0;
$qdata = mysql_query(“select kode,nama,deskripsi,harga from data order by kode”);
while($rdata = mysql_fetch_array($qdata))
{
$pkode = $rdata["kode"];
$pnama = $rdata["nama"];
$pketerangan = $rdata["deskripsi"];
$pharga = $rharga["harga"];
echo “<tr><td align=’center’>$pkode</td>
<td>$pnama</td>
<td>$pketerangan</td>
<td>$pharga</td>
<td align=’center’><a href=’edit.php?kode=$pkode&edit=1′>Edit</a></td></tr>”;
$i++;
}?>
</table>
<br>
<?php
if($edit==1)
{
$qdata2 = mysql_query(“select nama, deskripsi, harga from data where kode=’$kode’”);
while($rdata2 = mysql_fetch_array($qdata2))
{
$nama2 = $rdata2["nama"];
$keterangan2 = $rdata2["deskripsi"];
$harga2 = $rdata2["harga"];
}
echo “<p align=’center’>Ubah Data Barang <br><br>”;
echo “<form method=’post’ action=’edit_barang.php’>
<input type=’hidden’ name=’kodeg’ value=’kode’>
<input type=’hidden’ name=’kirim_edit’ value=1>”;
echo “<table border=0 width=500 align=’center’>”;
echo “<tr><td width=150>Kode </td>
<td><input type=’text’ name=’kode’ size=4 value=’kode’></td></tr>
<tr><td>Nama Barang </td>
<td><input type=’text’ name=’nama’ size=40 value=’nama2′></td></tr>
<tr><td valign=’middle’>deskripsi </td>
<td><textarea name=’definisi’ cols=40 rows=6>deskripsi2</textarea></td></tr>
<tr><td>Harga</td>
<td><input type=’text’ name=’harga’ size=40 value=’harga2′></td></tr>
<tr><td colspan=2 align=’center’><input type=’submit’ value=’EDIT’></td></tr>”;
echo “</table></form></p>”;
}
?>
[________________________________________________________________________________]
Hapus.php
<?php include "koneksi.php"; ?>
<table border="1" width="550" align="center">
<tr><td height=20 align="center" width=50><b>KODE</b></td>
<td align="center" width=170><b>NAMA</b></td>
<td align='center' width=250><b>DESKRIPSI</b></td>
<td align='center' width=80><b>HARGA</b></td></tr>
<?php
$hapus = (!empty($_GET['hapus']) ? $_GET['hapus'] : ");
if($hapus==1)
{
$kode = '$_GET[kode]';
$query2 = "delete from data where kode='$kode'";
mysql_query($query2);
}
$qdata= mysql_query("select kode,nama,deskripsi,harga from data order by kode");
$i = 0;
while($rdata= mysql_fetch_array($qdata))
{
$pkode= $rdata["kode"];
$pnama= $rdata["nama"];
$pdeskripsi= $rdata["deskripsi"];
$pharga= $rharga["harga"];
echo "<tr><td align='center'>$pkode</td><td >$pdeskripsi</td>
<td>$pnama_barang</td><td>$pharga</td><td align='center'>
<a href='hapus_data.php?kode=$pkode&hapus=1'>Hapus</a></td></tr>";
$i++;
}?>
SEKIAN DAN TERIMA KASIH ATAS PERHATIANNYA,SEMOEGA BERMANFAAT
[_______________________________________________________________________________]