Hello,
Can anyone help me find the logic behind this program?
input_berita_static.php
<?php
include('../includes/koneksi.php');
$post_id = isset($_POST['post_id']) ? $_POST['post_id'] : '';
$confirmation = isset($_POST['confirmation']) ? $_POST['confirmation'] : '';
$kategori = isset($_POST['kategori']) ? $_POST['kategori'] : '';
$news = isset($_POST['news']) ? $_POST['news'] : '';
$judul = isset($_POST['judul']) ? $_POST['judul'] : '';
$page = isset($_POST['page']) ? $_POST['page'] : '';
//Load berita
if (!empty($_GET['post_id'])){
$result = mysql_query("SELECT * FROM static_page WHERE post_id =".$_GET['post_id']) or die(mysql_error());
$data = mysql_fetch_array($result);
$post_id = $data['post_ID'];
$page = $data['page'];
$judul = $data['judul'];
$news = $data['isi_berita'];
}
else {
echo "unable to select data";
echo "id is empty";
}
//Simpan berita
if (isset($_POST['ok'])){
if (empty($_POST['post_id']))
{
$sqlstr = "INSERT INTO static_page(page, judul, isi_berita) VALUES('".$page."','".$judul."','".$news."')";
}
else
{
$sqlstr = "UPDATE static_page SET page='".$page."', judul='".$judul."', isi_berita='".$news."' WHERE id=".$_POST['post_id'];
}
$result = mysql_query($sqlstr) or die(mysql_error());
//Jika mode edit, maka tidak akan dikirimkan konfirmasi kepada subscriber
//if (empty($_REQUEST['id'])) kirimEmail($idKategori, $judul, $news);
$confirmation = ($result) ? "Data telah tersimpan." : "Gagal menyimpan data.";
}
?>
<div align="center">
<div style="width:800px;text-align:left;">
<?php echo $confirmation;?>
<form method="post" action="<?php echo $_SERVER['PHP_SELF']?>">
<input type="hidden" name="post_ID" value="<?php echo $post_id; ?>"/>
<table>
<tr>
<td>Page <font color="red">*</font></td>
<td><input type="text" size="50px" name="page" value="<?php echo $page; ?>" readonly></td>
</tr>
<tr>
<td>Judul</td>
<td><input type="text" size="50px" name="judul" value="<?php echo $judul; ?>"/></td>
</tr>
<tr>
<td valign="top">Isi berita</td>
<td>
<textarea cols="60" rows="10" id="news" name="news"><?php echo $news;?></textarea>
<script type="text/javascript">
var editor = CKEDITOR.replace('news');
</script> </td>
</tr>
<tr>
<td><input type="submit" name="ok" value="Simpan"/></td>
</tr>
</table>
</form>
</div>
</div>
</div>
I basically trying to update the news for post_id = 1 . It suppose to update the existing data instead of adding a new data (in post_id = 30), yet that's what happen.
How to make this program updating the existing data?
Thanks in advance.