RPL

satuanggara.blogspot.co.id

Monday, December 21, 2015

langkah membuat halaman view pada 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=iso-8859-1" />
<title>Untitled Document</title>
</head>

<body>
<h2>buku</h2>
<a href="form.php" target="contain" class="tombol" style="float:left;">daftar buku</a>
<a href="buku.php" target="contain" class="tombol" style="float:left;">tambah buku</a>
<a href="jumlah_buku.php" target="contain" class="tombol" style="float:left;">tambah jumlah buku</a>
<a href="kategori.php" target="contain" class="tombol" style="float:left;">kategori</a>
<a href="penerbit.php" target="contain" class="tombol" style="float:left;">penerbit</a>
<a href="pengarang.php" target="contain" class="tombol" style="float:left;">penerbit</a>

<h2>&nbsp;</h2>
<h2>&nbsp;</h2>
<h2>daftar buku</h2>
<table width="80%" border="0">
<?php
include "konek.php";
$r=mysql_query("select *from tbuku order by judul");
$i=1;
while($a=mysql_fetch_array($r)) {
?>
<tr>
<td width="23"><?php echo $i;?></td>
<td width="236"><?php echo $jud=$a['judul'];?></td>
<td width="23"><a href="detil_buku.php?id=<?php echo $a['id'];?>" class="link" target="contain">detil</a></td>
<td width="23"><a href="ubah_buku.php?id=<?php echo $a['id'];?>" class="link">ubah</a></td>
<td width="23"><a href="hapus.php?id=<?php echo $a['id'];?>" onclick="return confirm('apa anda yakin?')" class="link">hapus</a></td>
</tr>
<?php $i++;
}
?>
</table>
</body>
</html>

langkah membuat script update pada php

<?php
include "konek.php";
$judul=$_POST['judul'];
$cover=(rand()%99999);
$kategori=$_POST['kategori'];
$penerbit=$_POST['penerbit'];
$pengarang=$_POST['pengarang'];
$sinopsis=$_POST['sinopsis'];
$lokasi=$_POST['lokasi'];
$harga=$_POST['harga'];
$id=$_POST['id'];
mysql_query("update buku set judul='$judul',cover='$cover.jpg',kategori='$kategori',penerbit='$penerbit',pengarang='$pengarang',sinopsis='$sinopsis',lokasi='$lokasi',harga='$harga' where id='$id'");
$f=$_FILES['cover'];
$na=$f['name'];
if (!empty ($na)) {
mysql_query("update buku set cover='$cover.jpg' where id='$id'");
move_uploaded_file($_FILES['cover']['tmp_name'],"cover/$cover.jpg");
}
header("location:view.php");
?>

langkah membuat halaman ubah pada 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=iso-8859-1" />
<title>Untitled Document</title>
</head>

<body>
<div class="batas">
<h2>ubah buku</h2>
<?php
include"konek.php";
$id=$_GET['id'];
$r=mysql_query("select *from tbuku where id='$id'");
$a=mysql_fetch_array($r);
?>
<form action="update_buku.php" method="post" enctype="multipart/form-data" name="form1" id="form1">
<table width="70%" border="1">
  <tr>
    <td width="22%">judul</td>
    <td width="78%"><label>
      <input name="judul" value="<?php echo $a['judul'];?>" required="required" type="text" class="text" id="judul" />
    </label></td>
  </tr>
  <tr>
    <td>cover</td>
    <td><img src="cover/<?php echo $a['cover'];?>" width="50" style="float:left;margin-right:5px;"? /><label>
      <input  name="cover" type="file" class="text" id="cover" /> <br />pilih untuk mengcover buku</label></td>
  </tr>
  <tr>
    <td>kategori</td>
    <td><label>
      <select name="kategori" required="required" class="text" id="kategori">
 <option select="selected" value="<?php echo $a['kategori'];?>">-kategori-</option>
 <?php
 $rr=mysql_query("select *from kategori order by kat");
 while($ar=mysql_fetch_array($rr)) {
 ?>
 <option value="<?php echo $ar['kat'];?>"><?php echo $ar['kat'];?></option>
 <?php }?>
 </select>
    </label></td>
  </tr>
  <tr>
    <td>penerbit</td>
    <td><label>
<select name="penerbit" required="required" class="text" id="penerbit">
 <option select="selected" value="<?php echo $a['penerbit'];?>">-penerbit-</option>
 <?php
 $rr=mysql_query("select *from penerbit order by kat");
 while($ar=mysql_fetch_array($rr)) {
 ?>
 <option value="<?php echo $ar['kat'];?>"><?php echo $ar['kat'];?></option>
 <?php }?>
 </select>
    </label></td>
  </tr>
  <tr>
    <td>pengarang</td>
    <td><label>
      <select name="pengarang" required="required" class="text" id="pengarang">
 <option select="selected" value="<?php echo $a['pengarang'];?>">-pengarang-</option>
 <?php
 $rr=mysql_query("select *from pengarang order by kat");
 while($ar=mysql_fetch_array($rr)) {
 ?>
 <option value="<?php echo $ar['kat'];?>"><?php echo $ar['kat'];?></option>
 <?php }?>
 </select>
    </label></td>
  </tr>
  <tr>
    <td>sinopsis</td>
    <td><label>
      <textarea name="sinopsis" required="required" cols="45" rows="5" class="textarea" id="sinopsis"><?php echo $a['sinopsis'];?></textarea>
    </label></td>
  </tr>
  <tr>
    <td>lokasi</td>
    <td><label>
      <input name="lokasi" required="required" value="<?php echo $a['lokaasi'];?>" type="text" class="text" id="lokasi" />
    </label></td>
  </tr>
  <tr>
    <td>harga</td>
    <td><label>
      <input name="harga" required="required" value="<?php echo $a['harga'];?>" type="text" class="text" id="harga" />
    </label></td>
  </tr>
  <tr>
  <td><input name="id" type="hidden" id="id" value="<?php echo $id;?>" /></td>
<td><label>
<input name="button" type="submit" class="tombol" id="button" value="ubah" />
</label>
</td>
</tr>
</table>
</form>
</div>
</body>
</html>

langkah membuat scipt simpan pada php

<?php
include "konek.php";
$judul=$_POST['judul'];
$cover=(rand()%99999);
$kategori=$_POST['kategori'];
$penerbit=$_POST['penerbit'];
$pengarang=$_POST['pengarang'];
$sinopsis=$_POST['sinopsis'];
$lokasi=$_POST['lokasi'];
$harga=$_POST['harga'];
mysql_query("insert into buku(judul,cover,kategori,penerbit,pengarang,sinopsis,harga)
values('$judul','$cover.jpg','$kategori','$penerbit','$pengarang','$sinopsis','$harga')");
move_uploaded_file($_FILES['cover']['tmp_name'],"cover/$cover.jpg");
header("location:view.php");
?>

langkah membuat scipt koneksi pada php

<?php
$server="localhost";
$username="root";
$password="";
$database="dbperpus";

$konek=mysql_connect($server,$username,$password) or die ("koneksi gagal");
$konek=mysql_select_db($database) or die ("database tidak ditemukan");

if($konek) echo "koneksi berhasil";
?>

langkah membuat link hapus php

<?php
include "konek.php";
$id=$_GET['id'];
mysql_query("delete from buku where id='$id'");
header("location:view.php");
?>

langkah pertama membuat form php dari DW

<!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=iso-8859-1" />
<title>Untitled Document</title>
</head>

<body bgcolor="crimson"><form enctype="multipart/form-data"><h2> form buku </h2>
<table width="353" border="1">
  <tr>
    <td width="98">kode_id</td>
    <td width="239"><label>
      <input type="text" name="textField" />
    </label>    </td>
  </tr>
  <tr>
    <td>judul</td>
    <td><label>
      <input type="text" name="textfield1" />
    </label></td>
  </tr>
  <tr>
    <td>cover</td>
    <td><label>
      <input type="file" name="textfield2" />
    </label></td>
  </tr>
  <tr>
    <td>kategori</td>
    <td><label>
      <input type="text" name="textfield3" />
    </label></td>
  </tr>
  <tr>
    <td>penerbit</td>
    <td><label>
      <input type="text" name="textfield4" />
    </label></td>
  </tr>
  <tr>
    <td>pengarang</td>
    <td><label>
      <input type="text" name="textfield5" />
    </label></td>
  </tr>
  <tr>
    <td>sinopsis</td>
    <td><label>
      <input type="text" name="textfield6" />
    </label></td>
  </tr>
  <tr>
    <td>lokasi</td>
    <td><label>
      <input type="text" name="textfield7" />
    </label></td>
  </tr>
  <tr>
    <td>harga</td>
    <td><label>
      <input type="text" name="textfield8" />
    </label></td>
  </tr>
</table>
<input type="button" value="simpan" />
<input type="button" value="hapus" />
</form>
</body>
</html>