<?php
$host = "localhost";
$user = "root";
$password = "";
$database = "db_sewa";
$koneksi1=mysql_connect($host,$user,$password) or die(mysql_error());
$sqldb=mysql_select_db($database,$koneksi1) or die(mysql_error());
?>
EDIT.PHP
include "koneksi.php";
$ID_BUKU = $_GET['ID_BUKU'];
$q="SELECT * FROM buku WHERE ID_BUKU ='$ID_BUKU'";
$r=mysql_query($q) or die ($q);
$d=mysql_fetch_array($r);
if(isset($_POST['simpan'])){
$JUDUL=$_POST['JUDUL'];
$PENGARANG=$_POST['PENGARANG'];
$TANGGAL=$_POST['TANGGAL'];
$q="UPDATE buku SET JUDUL = '$JUDUL',
PENGARANG='$PENGARANG',
TANGGAL='$TANGGAL'
WHERE ID_BUKU = '$ID_BUKU'";
$r=mysql_query($q) or die(mysql_error());
if($r){
header("location:tampil.php");
}
else{
$msg = "Data tidak bisa diedit";
}
}
?>
<form action="edit.php?ID_BUKU=<?php echo $ID_BUKU;?>" method="POST">
<fieldset>
<legend>Form Edit Data Buku</legend>
<table>
<?php
if($msg!=''){
echo "$msg";
}
?>
<tr>
<td>Judul</td><td> : </td>
<td><input type="text" name="JUDUL" value='<?php echo $d[1];?>'></td>
</tr>
<tr>
<td>Pengarang</td><td> : </td>
<td><input type="text" name="PENGARANG" value='<?php echo $d[2];?>'></td>
</tr>
<tr>
<td>Tanggal</td><td> : </td>
<td><input type="date" name="TANGGAL" value='<?php echo $d[3];?>'></td>
</tr>
<tr>
<td><input type="submit" name="simpan" value="Edit"/>
<input type="submit" name="reset" value="Reset"/>
</td>
</tr>
</table>
</fieldset>
</form>
TAMPIL.PHP
<?php
include "koneksi.php";
$sql = "SELECT * FROM tb_sewa";
$res=mysql_query($sql,$koneksi) or die(mysql_error());
?>
<table border='1' width='100%' cellpadding='3' cellspacing='0' style='border-collapse:collapse'>
<tr align='center'>
<th width='3%'>No.</th>
<th width='20%'>Judul</th>
<th width='20%'>Pengarang</th>
<th width='20%'>Tanggal</th>
</tr>
<?php
$i = 1;
while ($data = mysql_fetch_array($res)){
if($i%2==0)$bg='#CCCCCC';
else $bg = '#FFFFFF';
echo "<tr bgcolor = '".$bg."'>
<td align='center'>".$i."</td>
<td>".$data["Judul"]."</td>
<td>".$data["Pengarang"]."</td>
<td>".$data["Tanggal"]."</td>
</tr>";
$i++;
}
?>
</table>
<a href='index.php?'>Tambah Baru</a></td>
Tidak ada komentar:
Posting Komentar