index.php
<?php
include 'koneksi.php';
$sql = mysql_query('select * from berita');
echo '<table border="1">';
echo '<tr>';
echo '<td>ID</td>';
echo '<td>JUDUL</td>';
echo '<td>ISI BERITA</td>';
echo '</tr>';
while($r = mysql_fetch_array($sql)) {
echo '<tr>';
echo '<td>'.$r['id_berita'].'</td>';
echo '<td>'.$r['judul'].'</td>';
echo '<td>'.$r['isi_berita'].'</td>';
echo '</tr>';
}
echo '</table>';
echo '<a href="create.php">Tambah</a>';
create.php
<?php
include 'koneksi.php';
if(isset($_POST['simpan'])) {
$id_berita = $_POST['id_berita'];
$judul=$_POST['judul'];
$isi_berita=$_POST['isi_berita'];
$sql=mysql_query("insert into berita(id_berita,judul,isi_berita)values('$id_berita','$judul','$isi_berita')");
echo("Data berhasil disimpan<br>");
echo"<meta http-equiv='refresh' content='0; url=index.php'>";
}
?>
<form method="post" action="">
<table width="477" border="1">
<tr>
<td width="153">ID</td>
<td width="11">:</td>
<td width="291"><input type="text" name="textfield" id="textfield" /></td>
</tr>
<tr>
<td>JUDUL</td>
<td>:</td>
<td><input type="text" name="judul" id="judul" /></td>
</tr>
<tr>
<td>ISI BERITA</td>
<td>:</td>
<td><textarea name="isi_berita" id="isi_berita" cols="45" rows="5"></textarea></td>
</tr>
</table>
<input type="submit" name="simpan" value="Simpan" />
</form>
koneksi.php
<?php
mysql_connect('localhost','root','1234');
mysql_select_db('azka');
0 komentar:
Posting Komentar