mardi 9 février 2016

Data from database don't show in my edit page

I'm trying to update the data from my database but the datas from my columns won't show up in my edit page. I don't find any error, but I think I have a logical error which I can't figure out where exactly.

Help, anyone?

edit_news.php // this is where the contents from my database to show to be able to update

<html>
<head>
<title>Edit</title>
</head>
<body>

<?php include_once('db.php'); ?>
<form action="/admin/update_news.php" method="post">
<input type="hidden" name="id" value="<?php echo $id; ?>"/>
<div>
<input type="text" name="title" value="<?php echo $title; ?> "/>
<input type="text" name="body" value="<?php echo $body; ?>"/>
<input type="submit" name="submit" value="Save Changes">
</div>
</form>
</body>
</html>

update_news.php // this is where the update function happens

<?php 
    date_default_timezone_set('Asia/Manila');
    include_once('db.php');
    if(isset($_POST['submit']))
    {
        if (is_numeric($_POST['id']))
        {
            $id = $_POST['id'];

        $title = mysql_real_escape_string(htmlspecialchars($_POST['title']));
        $body = mysql_real_escape_string(htmlspecialchars($_POST['body']));

        $servername = "localhost";
        $username="root";
        $password = "";
        $database = "zchs_alumni";
        $connection = new mysqli($servername, $username, $password, $database);
        if ($connection->connect_error) {
            die("Connection failed: " . $connection->connect_error);
        }

            mysql_query("UPDATE news SET title='$title', body='$body' WHERE id='$id'") or die(mysql_error());
            echo "<script type='text/javascript'>alert('Changes saved!!'); window.location.assign('/admin_profile.php');</script>";
            header("Location: admin_profile.php");
        }
    }
?>

// this is where the user click the edit link that will lead them to edit_news.php

<a href="/admin/edit_news.php?id=' . $row['id'] . '">EDIT</a>




Aucun commentaire:

Enregistrer un commentaire