PHP - 更新新闻错误

标签 php mysql

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

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");

}

?>

提前致谢...

最佳答案

我在您提到的问题部分中没有看到任何更新查询及其执行部分。在这种情况下,

您需要使用更新查询将记录更新到 MySQL 表中。

语法是,

  Update tablename set columnname='value' where  id='value' 

关于PHP - 更新新闻错误,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/19864844/

相关文章:

mysql - 选择从当月第一天开始的所有数据sql

php - 发布到 SQL 的端点问题

php - 使用 Python 进行基于规则的人工智能过滤

php , mysql 不允许连接到静态函数

PHP iconv() 将 "ä"转换为 "ae"但它应该是 "a"

mysql - 多个MySQL操作对表交互

mysql - 如何统计mysql中的数据然后在javafx中显示

php - 如何使用 Zend Framework 2 使用 Rest API

javascript - 正则表达式匹配模式 x 但返回任意字符串 y

mysql - dbslayer的现状?