gpt4 book ai didi

PHP - 更新新闻错误

转载 作者:行者123 更新时间:2023-11-30 01:03:40 25 4
gpt4 key购买 nike

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

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/

25 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com