gpt4 book ai didi

php - 先前插入的值会在页面刷新时自动插入

转载 作者:行者123 更新时间:2023-11-29 01:35:13 25 4
gpt4 key购买 nike

通过 PHP 通过 html 表单在数据库中插入值可能是什么查询或可能是什么解决方案,但每次我刷新页面时,先前插入的值都会再次插入?

if (isset($_POST["insert1"])) { 
$inrtno = $_POST["inrouteno"];
$instp = $_POST["instop"];

if ($inrtno !=''||$instp !='') {
$query = mysqli_query($datacon,"REPLACE INTO `stops`(`sn`, `routeno`, `stop`) VALUES ('NULL','$inrtno','$instp')");
echo "<script type='text/javascript'>alert('Insertion Successful !!!')</script>";
} else {
echo "<p>Insertion Failed <br/> Some Fields are Blank....!!</p>";
}
}

最佳答案

每次刷新页面时,您都在重新提交 POST 变量,因此 PHP 仍在运行。此外,您的查询有 SQL injection 的危险.考虑使用 PDO .

关于php - 先前插入的值会在页面刷新时自动插入,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/51999806/

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