Buatlah Project Baru / Folder Di C:/wamp/www. Beri Nama Tabelbarang - (Nim Anda) 2. Buat File Koneksi - PHP Dengan Code SBB

You might also like

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

1. Buatlah project baru / folder di c:\wamp\www.

Beri nama tabelbarang_[nim anda]


2. Buat file koneksi.php dengan code sbb:
<?php
$user = "mahasiswa";
$pwd = "12345";
$server = "192.168.2.25";
$db = "tokoxxx";
mysql_connect($server, $user, $pwd) or die("Gagal konek server");
mysql_select_db($db);
?>

3. Buatlah file table.php dengan code sbb


<?php
require_once(koneksi.php);
?>
<table border="1">
<tr>
<th>No.</th>
<th>Kode </th>
<th>Nama Barang</th>
<th>Harga</th>
<th>Stok</th>
<th>Edit</th>
</tr>
<?php
$query = SELECT * FROM barang;
$result = mysql_query($query);
$no=0;
while(($baris = mysql_fetch_array($result))==true)
{
echo <tr>;
echo <td>$no</td>;
echo <td>$baris[kdbrg]</td>;
echo <td>$baris[nmbrg]</td>;
echo <td>$baris[hrg]</td>;
echo <td>$baris[stok]</td>;
echo <td><button
onclick=\window.location=edit.php?key=$baris[kdbrg];\ > Edit </button>
</td>;
echo </tr>;
$no++;
}
?>
</table>

4. Buatlah file edit.php dengan code sbb:


<?php
require_once(koneksi.php);
?>
<form method=POST action=update.php>
<table border=1>
<?php
$key = $_GET[key];
$query = SELECT * FROM barang WHERE kdbrg = $key;
$result = mysql_query($query);
while(($baris = mysql_fetch_array($result))==true)
{
?>
<tr>
<td>Kode Barang</td><td>:</td>
<td><input type=text name=kdbrg value=<?=$baris[kdbrg]?>
enabled=0/></td>
</tr>
<tr>
<td>Nama Barang</td><td>:</td>
<td><input type=text name=nmbrg value=<?=$baris[nmbrg]?>/></td>
</tr>
<tr>
<td>Harga</td><td>:</td>
<td><input type=text name=hrg value=<?=$baris[hrg]?>/></td>
</tr>
<tr>
<td>Stok</td><td>:</td>
<td><input type=text name=stok value=<?=$baris[stok]?>/></td>
</tr>
<tr><td colspan=3><input type=submit value=Update /></tr></tr>
<?php
}
?>
</table>
</form>

5. Buatlah file update.php dengan code sbb


<?php
require_once(koneksi.php);
$kdbrg = $_POST[kdbrg];
$nmbrg = $_POST[nmbrg];
$hrg = (int)$_POST[hrg];
$stok = (int) $_POST[stok];
$query = UPDATE barang SET nmbrg=$nmbrg, hrg=$hrg, stok=$stok WHERE
kdbrg = $kdbrg;
$result = mysql_query($query);
if($result){
header(Location:pesan.php?pesan=1);
}else{
header(Location:pesan.php?pesan=0);
}
?>

6. Buatlah file pesan.php dengan code sbb:


<html> <body>
<script type=text/javascript>
<?php
$p = $_GET[pesan];
if($p == 0)
echo alert(\Gagal update data\); ;
else if($p == 1)
echo alert(\Berhasil update data\); ;
?>
window.location = index.php;
</script>
</body></html>

7. Buatlah index.php dengan code sbb


<html>
<header>
<title>Table Barang</title>
</header>
<body>
<?php
include_once(table.php);
?>
</body>
</html>

Dari hasil praktikum yang telah dilakukan pada hari ini, buatlah resume mengenai apa yang telah
dipelajari pada hari ini. Resume meliputi:

1. Apakah hasil program diatas, definisikan apa saja kelebihan dari program diatas dan
kekurangannya
2. Jelaskan perintah pada file pesan.php.
3. Apakah kegunaan perintah
echo alert(\Gagal update data\); ;

Kirimkan resume anda di http://192.168.2.25/resume

You might also like