【发布时间】:2021-12-08 01:51:06
【问题描述】:
我在运行以下解除函数时遇到了一些问题,
因此,带有我命名为 notification-success.php 的警报引导的页面如下所示:
<?php
$root = realpath(str_replace('\\', '/', $_SERVER['DOCUMENT_ROOT']) );
include ($root . '/insights/ss/onix.php');
$result = mysqli_query($mysqli,"select * from notifications where seen = 0");
if ($result)
{
if($result->num_rows) {
while($row = mysqli_fetch_assoc($result))
{?>
<div class='alert alert-success alert-dismissible' role='alert' style='margin-left:-12px;'>
<button type="button" class="close" onClick="updateId('<?php echo $row['id'];?>')" data-dismiss="alert" aria-label="Close" style="float:left!important; border:0; background:none;"><span aria-hidden="true">×</span></button>
<strong><span class="text-success" style="margin-top:-50px;"><i class='fa fa-check'></i> File has been moved successfully</strong><br>To confirm reading this message please press x button </span></div>
<?php }
}
}
?>
<script>
function updateId(id)
{
var xmlhttp = new XMLHttpRequest();
xmlhttp.open("GET", "dismisssuccess.php?id=" +id, true);
xmlhttp.send();
}
</script>
dismisssuccess.php 的动作文件如下:
<?php
if(isset($_GET['id']) && !empty($_GET['id']))
{
$id = $_GET['id'];
$ip = getenv('REMOTE_ADDR');
$root = realpath(str_replace('\\', '/', $_SERVER['DOCUMENT_ROOT']) );
include ($root . '/insights/ss/onix.php');
$update = "UPDATE notifications SET seen = 1 , seenby = '$ip' WHERE id = '".$id."'";
if (mysqli_query($mysqli, $update))
{
echo "success";
}
else
{
echo "There is some error";
}
die;
}
?>
现在,当我按下 x 时,更新语句实际上并没有运行,同时,当我通过 http 打开具有相关 id 的dismisssuccess 文件时,它可以正常工作且没有错误并且是否需要更新,只有当我更改要更新的表。
有人知道这个问题背后的可能原因吗?
提前谢谢你
【问题讨论】:
-
您尝试过什么来解决问题?你被困在哪里了?另外,请注意您的
UPDATE查询对 SQL 注入开放 -
您生成的 HTML 标记嵌套不正确.. 一部分以
<strong><span<开头但以</strong><br>To confirm reading this message please press x button </span>结尾 -
另外——你的 ajax 函数对任何返回的内容都不做任何事情,那么为什么还要在 php 中生成任何内容呢?
-
警告:您对SQL Injections 持开放态度,应该使用参数化的prepared statements,而不是手动构建查询。它们由PDO 或MySQLi 提供。永远不要相信任何形式的输入!即使您的查询仅由受信任的用户执行,you are still in risk of corrupting your data。 Escaping is not enough!
-
@NicoHaase 我尝试过的是 1. 使用 http 和目标 id 运行操作文件和更新 stmt 仅与通知文件分开工作 2. 更改要更新的目标表也使我的代码成为充分发挥作用