【发布时间】:2018-10-17 10:20:14
【问题描述】:
我正在使用此代码
<?php
include('connection.php');
$heading = $_POST['upd_head'];
$note = $_POST['upd_text'];
$post_id = $_POST['up_post_id'];
$supd_head= "UPDATE posts SET heading= ?, note=? WHERE post_id=?";
$stmt_head= mysqli_stmt_init($db_conx);
if(!mysqli_stmt_prepare($stmt_head, $supd_head)){
echo "sql is not ready";
}
else{
mysqli_stmt_bind_param($stmt_head, "sss", $heading,$note,$post_id);
mysqli_stmt_execute($stmt_head);
}
?>
当我给出这个输入时
<script>alert('hack');</script>
它按原样保存在数据库中,并在我更新数据后刷新页面时发出警报消息。为什么不先清理数据?但我认为使用prepare语句时没有使用mysqli_real_escape_string。
【问题讨论】:
-
你如何回显变量?
-
“为什么不先清理数据?” - 因为这绝对不是它的工作……?它的工作是确保您向其输入的任何数据都不会在将数据插入数据库时造成问题。 “并在更新数据后刷新页面时发出警告消息” - 这是因为您在将数据输出到页面时没有正确处理数据。数据库与此几乎没有关系。
-
谢谢你的回答,现在我明白了