The code below is from tutorial, my problem is my work dont work and the video tutorial is corrupted, i missed something for sure, the WHERE articles_id
='$update_id' condition in query is not working, it wont find the corrent id to be editted. Please help.
<?php require 'includes/verifycred.php'; ?>
<!DOCTYPE html>
<html lang="en">
<head>
<title>Geostigma Technology</title>
<meta charset="utf-8" />
<link rel="stylesheet" href="style.css" type="text/css" />
<meta name="viewport" content="width=device-width, initial-scale=1.0">
</head>
<body class="body">
<header class="mainHeader">
<nav>
<ul>
<li>
<a href="adminpage.php">ADMIN PANEL</a>
</li>
</ul>
</nav>
</header>
<?php include 'sideBar.php' ?>
<div align="center">
<?php
include 'connect.php';
if(isset($_GET['edit'])){
$edit_id = $_GET['edit'];
$edit_query = "SELECT * FROM articles WHERE articles_id ='$edit_id'";
$run_edit = mysql_query($edit_query);
while ($edit_row=mysql_fetch_array($run_edit)){
$articles_id = $edit_row['articles_id'];
$articles_title = $edit_row['articles_title'];
$articles_category = $edit_row['articles_category'];
$articles_image = $edit_row['articles_image'];
$articles_content = $edit_row['articles_content'];
}
}
?>
<div>
<form method="post" action="edit.php?edit_form=<?php echo $articles_id;?>" enctype="multipart/form-data">
<table border="0">
<tr>
<td align="right">Title</td>
<td><input type="text" name="title" value="<?php echo $articles_title; ?>"></td>
</tr>
<tr>
<td align="right">Category</td>
<td>
<select name="category">
<option value="computers">Computers</option>
<option value="smartphones">Smartphones</option>
</select>
</td>
</tr>
<tr>
<td align="right">Image</td>
<td align="left">
<img src="../<?php echo $articles_image; ?>" width = "200" height = "200">
<input type = "file" name="image">
</td>
</tr>
<tr>
<td align="right">Content</td>
<td><textarea type="text" name="content" cols="30" rows="10"><?php echo $articles_content; ?>"</textarea></td>
</tr>
<tr>
<td></td>
<td><input type="submit" name="update" value="Update Now"></td>
</tr>
</table>
</form>
<?php
include 'connect.php';
if (isset($_POST['update'])){
$update_id = $_GET['edit_form'];
$time = time() + 25200;
$articles_date1 = date('Y-m-d h:i:s', $time);
$articles_title1 = htmlentities($_POST['title']);
$articles_category1 = htmlentities($_POST['category']);
$articles_image1 = $_FILES['image']['name'];
$image_tmp = $_FILES['image']['tmp_name'];
$articles_content1 = htmlentities($_POST['content']);
if ($articles_title1=='' or $articles_content1==''){
echo "<script>alert('All fields are required.', ' ')</script>";
exit();
}else{
move_uploaded_file($image_tmp, "../$articles_image1");
$update_query = "update `articles` set `articles_date`='$articles_date1', `articles_title`='$articles_title1, `articles_category`='$articles_category1', `articles_image`='$articles_image1', `articles_content`='$articles_content1' WHERE `articles_id`='$update_id'";
if(mysql_query($update_query)){
echo "<script>alert('Article has been updated.')</script>";
echo "<script>window.open('adminpage.php','_self')</script>";
}
}
}
?>
</div>
</body>
</html>