Kamis, 27 Desember 2012

PHP (Latihan 21)

Posted by Unknown On Kamis, Desember 27, 2012 | No comments

Tabel Tamu (Simpan Dengan Nama buku_tamu)
Gambar 1.0
Ketika Button Simpan Diclick Maka Tampil Seperti Gambar 2.0
Gambar 2.0
Ketika Click "Lihat Data" Maka Tampil Seperti Gambar 3.0
Ketika Click "Kembali" Maka Tampil Seperti Gambar 1.0
Gambar 3.0
Ketika Click "Edit" Maka Tampil Seperti Gambar 4.0
Ketika Click "Delete" Maka Tampil Seperti 5.0
Ketika Click "Kembali Input Buku" Tampil Seperti Gambar 1.0
Gambar 4.0
Ketika Button Update Diclick Maka Tampil Seperti Gambar 4.1
Gambar 4.1
Ketika Click "Edit" Maka Tampil Seperti Gambar 4.0
Ketika Click "Delete" Maka Tampil Seperti Gambar 5.0
Ketika Click "Kembali Input Buku" Maka Tampil Seperti Gambar 1.0
Gambar 5.0
Ketika Click "Kembali Input Buku" Maka Tampil Seperti Gambar 1.0
Bila Masih Ada Data Yang Tersisa Maka Tampil Edit & Delete
Ketika Click "Edit" Maka Tampil Seperti Gambar 4.0
Ketika Click "Delete" Maka Tampil Seperti Gambar 5.0
NB*: Anda Harus Buat Database Terlebih Dahulu

Coding/Listing Koneksi (Simpan Dengan Nama koneksi.php) :


<?php
$koneksi=mysql_connect("localhost","root","password") or die(mysql_error());
mysql_select_db("latihan_sql",$koneksi) or die (mysql_error());
?>

Coding/Listing Gambar 1.0 (Simpan Dengan Nama latihan_input.php) :


<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
<html xmlns="http://www.w3.org/1999/xhtml">
<head>
<meta http-equiv="Content-Type" content="text/html; charset=utf-8" />
<title>Untitled Document</title>
</head>

<body>
<form action="latihan_insert.php" method="post">
<h1 align="center"><font face="Castellar">Input Buku Tamu</font></h1>
<br />
<table width="600" border="0" cellspacing="0" cellpadding="0" align="center">
 <tr>
    <td>&nbsp;NIM</td>
    <td>&nbsp;<input name="nim" type="text" size="10" maxlength="10" /></td>
  </tr>
  <tr>
    <td>&nbsp;Nama</td>
    <td>&nbsp;<input name="nama" type="text" size="30" maxlength="30" /></td>
  </tr>
  <tr>
    <td>&nbsp;Email</td>
    <td>&nbsp;<input name="email" type="text" size="20" maxlength="20" /></td>
  </tr>
  <tr>
    <td valign="top">&nbsp;Komentar</td>
    <td>&nbsp;<textarea name="komentar" cols="25" rows="5"></textarea></td>
  </tr>
  <tr>
    <td colspan="2" align="center">&nbsp;<input name="bsimpan" type="submit" value="Simpan" />
      <input name="breset" type="reset" id="breset" value="Batal" /></td>
    </tr>
</table>
</form>
</body>
</html>

Coding/Listing Gambar 2.0 (Simpan Dengan Nama latihan_insert.php) :

<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
<html xmlns="http://www.w3.org/1999/xhtml">
<head>
<meta http-equiv="Content-Type" content="text/html; charset=utf-8" />
<title>Untitled Document</title>
</head>

<body>
<?php
include "koneksi.php";

$perintah=mysql_query("insert into buku_tamu(nim,nama,email,komentar)values('$nim','$nama','$email','$komentar')",$koneksi) or die (mysql_error());

echo "<h3><marquee>Terima Kasih $nama, Komentar Anda Sanga Kami Harapkan</h3></marquee>";
?>
<br />
<br />
<br />
<a href="tampil_latihan.php">Lihat Data</a>
<a href="latihan_input.php">Kembali</a>
</body>
</html>

Coding/Listing Gambar 3.0 (Simpan Dengan Nama tampil_latihan.php) :

<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
<html xmlns="http://www.w3.org/1999/xhtml">
<head>
<meta http-equiv="Content-Type" content="text/html; charset=utf-8" />
<title>Untitled Document</title>
</head>

<body>
<?php
include "koneksi.php";

$hasil=mysql_query("select * from buku_tamu",$koneksi);
$jumlah=mysql_num_rows($hasil);
echo "Jumlah Tamu:$jumlah";
echo "<br><br>";
echo "<table border=1>
<tr>
<th>NIM</th>
<th>Nama</th>
<th>Email</th>
<th>Komentar</th>
<th>Action</th>
</tr>";
while($row=mysql_fetch_array($hasil))
{
echo "<tr>";
echo "<td>$row[nim]";
echo "<td>$row[nama]";
echo "<td>$row[email]";
echo "<td>$row[komentar]";
echo "<td><a href=edit.php?nim=$row[0]>Edit</a>&nbsp;<a href=delete.php?nim=$row[0]>Delete</a></td>";
echo "</tr>";
}
echo "</table>";
?>
<br />
<a href="latihan_input.php">Kembali Input Buku</a>
</body>
</html>

Coding/Listing Gambar 4.0 (Simpan Dengan Nama edit.php) :

<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
<html xmlns="http://www.w3.org/1999/xhtml">
<head>
<meta http-equiv="Content-Type" content="text/html; charset=utf-8" />
<title>Untitled Document</title>
</head>

<body>
<?php
include "koneksi.php";

$hasil=mysql_query("select * from buku_tamu where nim='$nim'",$koneksi) or die(mysql_error());
while($row=mysql_fetch_array($hasil))
{
echo "<form method=post action=update.php>";
echo "<pre>";
$nim=$row["nim"];
$nama=$row["nama"];
$email=$row["email"];
$komentar=$row["komentar"];
echo "NIM : <input type=text size=10 name=nim value=$nim><br>";
echo "Nama : <input type=text size=30 name=nama value=$nama><br>";
echo "Email : <input type=text size=25 name=email value=$email><br>";
echo "Komentar : <textarea rows=4 cols=25 name=komentar>$komentar</textarea><br>";
echo "<input type=submit value=Update>";
echo "</pre>";
echo "</form>";
}
?>
</body>
</html>

Coding/Listing Gambar 4.1 (Simpan Dengan Nama update.php) :

<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
<html xmlns="http://www.w3.org/1999/xhtml">
<head>
<meta http-equiv="Content-Type" content="text/html; charset=utf-8" />
<title>Untitled Document</title>
</head>

<body>
<?php
include "koneksi.php";

$hasil=mysql_query("update buku_tamu set nama='$nama',email='$email',komentar='$komentar' where nim='$nim'",$koneksi) or die(mysql_error());
echo "Data Telah Diperbaharui";
include ("tampil_latihan.php");
?>
</body>
</html>

Coding/Listing Gambar 5.0 (Simpan Dengan Nama delete.php) :

<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
<html xmlns="http://www.w3.org/1999/xhtml">
<head>
<meta http-equiv="Content-Type" content="text/html; charset=utf-8" />
<title>Untitled Document</title>
</head>

<body>
<?php
include "koneksi.php";

$query=stripslashes($query);
$query=mysql_query("delete from buku_tamu where NIM='$nim'",$koneksi) or die(mysql_error());
if($query)
echo "<h2>Data Dengan nim=$nim Telah Terhapus</h3>";
include ("tampil_latihan.php");
?>
</body>
</html>

Kamis, 20 Desember 2012

PHP (Pra UAS)

Posted by Unknown On Kamis, Desember 20, 2012 | No comments
Tabel DVD (Simpan Dengan dvd)
Gambar 1.0
Ketika Button Simpan Di Click Maka Tampil Gambar 2.0
Gambar 2.0
Ketika "Lihat" Diclick Maka Tampil Gambar 3.0
Gambar 3.0
Ketika "Back" Diclick Maka Tampil Gambar 1.0
NB : Buat Terlebih Dahulu Databasenya..!!

Sebelum Membuat input.php Buat Terlebih Dahulu koneksi.php.
Coding/Lising koneksi.php:


<?php
$koneksi=mysql_connect("localhost","root","password") or die(mysql_error());
mysql_select_db("belajar_sql",$koneksi) or die (mysql_error());
?>

NB : Pada Bagian Password isi sesuai yang anda buat :)
         Pada Bagian "belajar_sql" ini maksudnya databases yang anda buat..!!


Coding/Listing Gambar 1.0 (Simpan Dengan input.php) :


<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
<html xmlns="http://www.w3.org/1999/xhtml">
<head>
<meta http-equiv="Content-Type" content="text/html; charset=utf-8" />
<title>Untitled Document</title>
</head>

<body>
<br /><br />
<form action="simpan.php" method="post">
<table width="331" border="2" cellspacing="0" cellpadding="0" align="center">
  <tr>
    <td colspan="2" align="center"><font face="Comic Sans MS">&nbsp;Form Input Data DVD</font></td>
    </tr>
  <tr>
    <td width="159">&nbsp;Kode Transaksi</td>
    <td width="164">&nbsp;<input name="notrans" type="text" size="10" maxlength="10" /></td>
  </tr>
  <tr>
    <td>&nbsp;Kode DVD</td>
    <td>&nbsp;<select name="kddvd">
      <option>--Click Here--</option>
      <option value="D001">D001</option>
      <option value="D002">D002</option>
      <option value="D003">D003</option>
    </select></td>
  </tr>
  <tr>
    <td>&nbsp;Jumlah Beli</td>
    <td>&nbsp;<input name="jumbel" type="text" size="5" maxlength="5" /></td>
  </tr>
  <tr>
    <td colspan="2" align="center">&nbsp;<input name="bsimpan" type="submit" value="Simpan" />&nbsp;<input name="bcancel" type="reset" value="Batal" /></td>
    </tr>
</table>

</form>
</body>
</html>

Coding/Listing Gambar 2.0 (Simpan Dengan Nama simpan.php) :

<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
<html xmlns="http://www.w3.org/1999/xhtml">
<head>
<meta http-equiv="Content-Type" content="text/html; charset=utf-8" />
<title>Untitled Document</title>
</head>

<body>
<?php
include "koneksi.php";

$notrans=$_POST['notrans'];
if($kddvd=='D001')
{
$judul="Kambing Jantan";
$harga=50000;
}
elseif($kddvd=='D002')
{
$judul="Monster VS Alien";
$harga=40000;
}
else
{
$judul="New Moon";
$harga=30000;
}
$jumbel=$_POST['jumbel'];
$total=$harga*$jumbel;

$simpan=mysql_query("insert into dvd(notrans,kd_dvd,judul,harga,jumlah_beli,total) values ('$notrans','$kddvd','$judul','$harga','$jumbel','$total')",$koneksi) or die (mysql_error());
?>
Silakan Lihat Data<br />
<a href="tampil.php">Lihat</a>
</body>
</html>

Coding/Listing Gambar 3.0 (Simpan Dengan Nama tampil.php) :

<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
<html xmlns="http://www.w3.org/1999/xhtml">
<head>
<meta http-equiv="Content-Type" content="text/html; charset=utf-8" />
<title>Untitled Document</title>
</head>

<body>
<font size="4">Data DVD</font><br />
<?php
include "koneksi.php";

$query=mysql_query("select * from dvd",$koneksi);
$jumlah=mysql_num_rows($query);
echo "<pre>";
echo "<b><u>Jumlah DVD : $jumlah</u></b>";
while($baris=mysql_fetch_row($query))
{
echo "<br>";
echo "No Transaksi : $baris[0]<br>";
echo "Kode DVD : $baris[1]<br>";
echo "Judul : $baris[2]<br>";
echo "Harga : $baris[3]<br>";
echo "Jumlah Beli : $baris[4]<br>";
echo "Total : $baris[5]<br>";
echo "<br>";
}
echo "<p><a href=input.php>Back</a>";
echo "</pre>";
?>
</body>
</html>

Blog Archive

Blogroll