0

我在某些新闻网站上的编辑按钮遇到了一些问题...欢迎任何类型的帮助...这是我的代码..我将忽略不相关的代码

admin_first.php

<?php

    $connection = mysqli_connect(DB_HOST, DB_USER, DB_PASS, DB_BASE);
    $query = "SELECT * FROM news ORDER BY id";
    $result = mysqli_query($connection, $query);

    while($row = mysqli_fetch_array($result))
    {
        $id[] = (int) $row['id'];
        $header[] = htmlspecialchars($row['header']);
        $text[] = htmlspecialchars($row['text']);
        $picture[] = htmlspecialchars($row['pictures']);
        $date[] = $row['time'];
    }
    if(mysqli_num_rows($result) != 0)
    {
        for($i=0; $i<count($id); $i++)
        {
            echo '<div class="new_item"><h2>' . $header[$i] . '</h2><p class="text">' . $text[$i] . '</p><a href="' . $picture[$i] . '" target="_blank"><img src="' . $picture[$i] . '"/></a><p class="time">' . $date[$i] . '</p></div>
                <div class="buttons"><form><input type="button" name="delete" id="delete" onclick="window.location.href=\'process_buttons.php?delete=' . $id[$i] . '\'" 
                    value="Obri�i vest"/><input type="button" name="edit" id="edit" onclick="window.location.href=\'process_buttons.php?edit=' . $id[$i] . '\'" value="Izmeni vest"/></form></div>';
        }
    }
    mysqli_close($connection);
    ?>

这是

process_buttons.php

<?php
include 'functions.php';
include 'constants.php';

is_logged_in("admin.php");

$connection = mysqli_connect(DB_HOST, DB_USER, DB_PASS, DB_BASE);
$safe_id = filter_input(INPUT_GET, 'delete', FILTER_SANITIZE_STRING);

if(!empty($_GET['delete']))
{
    $query = "DELETE FROM news WHERE id='{$safe_id}'";
    $result = mysqli_query($connection, $query) or die(mysqli_error());

    header("Location: admin_first.php");
}
else
{

?>

这是删除部分,工作正常..

问题在于这部分:

<?php   

$safe_id = (int) $_GET['edit']; 
$query = "SELECT * FROM news WHERE id='{$safe_id}'";
$result = mysqli_query($connection, $query);

while($row = mysqli_fetch_array($result))
{
    $header = htmlspecialchars($row['header']);
    $text = nl2br(htmlspecialchars($row['text']));
    $picture = $row['picture'];
    header("Location: admin_first.php");

}

?>

提前致谢...

4

1 回答 1

0

I don't see any update query and its execution part in your problem mentioned section. In that case,

You need to use update query to update your records into MySQL table.

Syntax is,

  Update tablename set columnname='value' where  id='value' 
于 2013-11-08T17:29:53.403 回答