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>

if your link for edit is edit.php?edit=1234
$_GET['edit'] in your php code is works fine.

but if not there is something wrong with $_GET['edit_form'] because the ID in the form not found unless there is ID from $_GET['edit'];

put at the top of the page error_reporting(E_ALL); and see what errors come from the page.

no errors at all... try my website here
user: a
pass: a

Try this:

$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'" or die(mysql_error());

this line also needs to closed with a ', articles_title='$articles_title1,`

error message still not showing even if i remove web styling

this pop up msg also not working

echo "<script>alert('Article has been updated.')</script>";

Thats because its never reaching that point yet. Make sure that all your lines in the update query are closed off properly. You are getting an error in there. copy and paste this into you code.

    $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'" or die(mysql_error());

Also just noticed that you have your connect.php in there multiple times, you only need it once in there. Move it to the top of the page where you have <?php require 'includes/verifycred.php'; ?>

this is the error, a single qoute, i feel bad for this for 3 days hehe wondering why not working, verifycred.php has connect.php, so i removed all other connect.php, thank you!

articles_title='$articles_title1, 

Your welcome.

Be a part of the DaniWeb community

We're a friendly, industry-focused community of developers, IT pros, digital marketers, and technology enthusiasts meeting, networking, learning, and sharing knowledge.