**I can't update inserted data via GUI, Its working well on inserting records before I modify it, and when am trying to modify in order to update inserted data its not update as I expect to happen. I can display inserted data well by echo them to GUI
Below is the update form that Am trying to create
Please help me. Am just a beginner, thanks**
<?php
include ("db_con.php");
if(isset($_POST['update'])){
$update_id = $post_id;
//getting the text data from the fields
$post_title = $_POST["post_title"];
$category_id = $_POST["category_id"];
$post_author = $_POST["post_author"];
$post_keywords = $_POST["post_keywords"];
$post_content = $_POST["post_content"];
//getting the image form the field
$post_image = $_FILES['post_image']['name'];
$post_image_tmp = $_FILES['post_image']['tmp_name'];
move_uploaded_file($post_image_tmp,"news_images/$post_image");
$update = "update posts set
post_title='$post_title', post_date=CURDATE(), category_id='$category_id', post_author='$post_author', post_keywords='$post_keywords', post_image='$post_image', post_content='$post_content' where post_id='$update_id'";
//$query=mysqli_query($con, $sql);
$run = mysqli_query($con, $update);
if($run)
{
echo "<script>alert('Product has been updated')</script>";
}
else
{
echo "<script>alert('There is something wrong!')</script>";
}
}
?>
<!doctype html>
<html>
<head>
<!-- starting of text editor -->
<script src="//cdn.tinymce.com/4/tinymce.min.js"></script>
<script>tinymce.init({ selector:'textarea' });</script>
<!-- ending of text editor -->
<meta charset="utf-8">
<title>Insert Post Form</title>
</head>
<body>
<?php
include("db_con.php");
if(isset($_GET['edit_post'])){
$edit_id = $_GET['edit_post'];
$select_post = "select * from posts where post_id='$edit_id'";
$run_query = mysqli_query($con, $select_post);
while ($row_post=mysqli_fetch_array($run_query)){
$post_id = $row_post['post_id'];
$title = $row_post['post_title'];
$post_cat = $row_post['category_id'];
$author = $row_post['post_author'];
$keywords = $row_post['post_keywords'];
$image = $row_post['post_image'];
$content = $row_post['post_content'];
}
}
?>
<div class='form'>
<form action="" method="post" enctype="multipart/form-data">
<table width="800" align="center" border="2">
<tr>
<td colspan="6" align="center" bgcolor="#FF6600"><h1>Update Post:</h1></td>
</tr>
<tr>
<td align="right" bgcolor="#FF6600"><strong>Post Title:</strong></td>
<td><input type="text" name="post_title" size="60" value="<?php echo $title; ?>"/></td>
</tr>
<tr>
<td align="right" bgcolor="#FF6600"><strong>Post Categories:</strong></td>
<td>
<select name="category_id">
<?php
$get_cats = "select * from categories where cat_id='$post_cat'";
$run_cats = mysqli_query($con, $get_cats);
while ($cats_row=mysqli_fetch_array($run_cats)){
$cat_id=$cats_row['cat_id'];
$cat_title=$cats_row['cat_title'];
echo "<option value='$cat_id'>$cat_title</option>";
}
$get_more_cats = "select * from categories";
$run_more_cats = mysqli_query($con, $get_more_cats);
while($row_more_cats=mysqli_fetch_array($run_more_cats)){
$cat_id=$row_more_cats['cat_id'];
$cat_title=$row_more_cats['cat_title'];
echo "<option value='$cat_id'>$cat_title</option>";
}
?>
</select>
</td>
</tr>
<tr>
<td align="right" bgcolor="#FF6600"><strong>Post Author:</strong></td>
<td><input type="text" name="post_author" size="60" value="<?php echo $author; ?>" /></td>
</tr>
<tr>
<td align="right" bgcolor="#FF6600"><strong>Post Keywords:</strong></td>
<td><input type="text" name="post_keywords" size="60" value="<?php echo $keywords; ?>" /></td>
</tr>
<tr>
<td align="right" bgcolor="#FF6600"><strong>Post Image:</strong></td>
<td><input type="file" name="post_image" size="50"/> <img src="news_images/<?php echo $image; ?>" width="60" height="60" /></td>
</tr>
<tr>
<td align="right" bgcolor="#FF6600"><strong>Post Content:</strong></td>
<td><textarea name="post_content" rows="15" cols="40"><?php echo $content; ?></textarea></td>
</tr>
<tr>
<td colspan="6" align="center" bgcolor="#FF6600"><input type="submit" name="update" value="Update Now"></td>
</tr>
</table>
</form>
</div>
</body>
</html>