Pertemuan 13 Pemrograman Web 2
Pertemuan 13 Pemrograman Web 2
Pertemuan 13 Pemrograman Web 2
(LANJUTAN)
<?
include "koneksi.php";
?>
<h1>Form Berita</h1>
<form name=article method=post action=article.php>
<table width="100%" border="0" cellspacing="0" cellpadding="0">
<tr>
<td width="18%">Judul</td>
<td width="2%">:</td>
<td width="80%"><input type="text" name="title" size="30"
class="masukan"></td>
</tr>
<tr>
<td>Penulis</td>
<td>:</td>
<td><input type="text" name="author" size="30" class="masukan"></td>
</tr>
<tr>
<td>Lead</td>
<td>:</td>
<td><textarea name="abstraksi" rows="4" cols="45"></textarea></td>
</tr>
<tr>
<td>Content</td>
<td>:</td>
<td><textarea name="content" rows="8" cols="45" ></textarea></td>
</tr>
<tr>
<td> </td>
<td> </td>
<td> </td>
</tr>
<tr>
<td> </td>
<td> </td>
<td><input type="submit" name="Submit" value="Add" class="tombol">
<input type="reset" name="batal" value="Reset" class="tombol"></td>
</tr>
</table>
</form>
Proses Penambahan Artikel
<?
include "koneksi.php";
$judul= $_POST['title'];
$penulis = $_POST['author'];
$lead = $_POST['abstraksi'];
$isi = $_POST['content'];
$time=date("d M Y, H:i");
$lead = str_replace("\r\n","<br>",$lead);
$content = str_replace("\r\n","<br>",$content);
if($result){
echo "<h3 align=center>Proses penambahan artikel berhasil</h3>";
echo "<A href=\"tampil_articles.php\">List</A>";
}else{
echo "<h2 align=center>Proses penambahan artikel tidak berhasil</h2>";
}
?>
<?php
include "koneksi.php";
$perintah="SELECT * FROM articles ORDER BY articleID DESC";
$hasil=mysql_db_query($dbname,$perintah);
echo("
<h2>List Artikel</h2>
<br><UL>
");
while ($row=mysql_fetch_array($hasil))
{
echo("
<LI>$row[1] $row[2] $row[waktu] <a
href=\"edit_article.php?articleID=$row[0]\">Edit</a>
<a
href=\"delete.php?articleID=$row[0]\">Hapus</a></LI><br>");
}
echo("</table>");
echo "<br><a href=\"add_article.php\">Tambah</a>";
echo "<br><a href=\"adminpanel.php\">Admin Panel</a>";
?>
<?
include "koneksi.php";
$articleID = $_GET['articleID'];
// Query satu record artikel dari tabel sesuai nilai $articleID
$perintah="SELECT * FROM articles WHERE articleID =\"$articleID\"";
$hasil=mysql_db_query($dbname,$perintah);
$row=mysql_fetch_array($hasil);
$time=date("d M Y, H:i");
?>
<h1>Form Berita</h1>
<form name=article method=post action=update_article.php>
<input type="hidden" name="ID" value="<? echo "$row[articleID]" ?>">
<table width="100%" border="0" cellspacing="0" cellpadding="0">
<tr>
<td width="18%">Judul</td>
<td width="2%">:</td>
<td width="80%"><input type="text" name="title" size="50" class="masukan"
value="<? echo "$row[judul]" ?>"></td>
</tr>
<tr>
<td>Penulis</td>
<td>:</td>
<td><input type="text" name="author" size="50" class="masukan"
value="<? echo "$row[penulis]" ?>"></td>
</tr>
<tr valign="top">
<td>Lead</td>
<td>:</td>
<td><textarea name="abstraksi" rows="4" cols="50">
<? echo "$row[lead]" ?></textarea></td>
</tr>
<tr valign="top">
<td>Content</td>
<td>:</td>
<td><textarea name="content" rows="4" cols="50">
<? echo "$row[content]" ?></textarea></td>
</tr>
<tr>
<td> </td>
<td> </td>
<td> </td>
</tr>
<tr>
<td> </td>
<td> </td>
<td>
<input type="submit" name="masuk" value="Update" class="tombol">
<input type="reset" name="hapus" value="Cancel" class="tombol"></td>
</tr>
</table>
</form>
<?
include "koneksi.php";
$time=date("d M Y, H:i");
//$lead = str_replace("\r\n","<br>",$lead);
//$content= str_replace("\r\n","<br>",$content);
$update="UPDATE articles SET judul='$title', penulis='$author',
lead='$abstraksi',
content='$content', waktu='$time' WHERE articleID ='$ID'";
$hasil=mysql_db_query($dbname,$update);
if ($hasil) {
echo "Artikel berhasil di update<br>";
echo "<a href=\"tampil_articles.php\">List</a>";
} else {
echo "Artikel gagal di update";
}
?>
<?php
include "koneksi.php";
$articleID = $_GET['articleID'];
if ($hasil) {
echo "Artikel berhasil dihapus<br>";
echo "<a href=\"edit_articles.php\">Back</a>";
} else {
echo "Komentar gagal dihapus. Kemungkinan terjadi kegagalan koneksi
ke database MySQL.";
}
?>