每当我在php页面中提交反馈时,它都会在数据库中记录文本,但是当我刷新页面时,mysql数据库中的数据就会重复。我的代码有什么问题?
<?php
include('session.php');
if(isset($_POST['submit'])){
$fidbak = mysqli_real_escape_string($db,$_POST['fidbak']);
$sql = "INSERT INTO tblfeedback VALUES ('$user_check',
'$FirstName $MiddleName $LastName', '$fidbak')";
$result = mysqli_query($db,$sql) or die(mysql_error());
}
?>
<!doctype>
<html>
<head>
<link rel="stylesheet" type="text/css" href="css/feedback.css">
<meta name="viewport" content="width=device-width, initial-scale=1">
<form action="" method="POST">
</head>
<body>
<div class="mainDiv">
<div class="mainFeedback">
<div class="fback">
<textarea rows="20" cols="65" placeholder="What can we do?" name="fidbak"></textarea>
<button id="subm" type="submit" name="submit">Submit</button><br><br>
</span>
</div>
</div>
</div>
<script src="sameFunctions.js"></script>
<script src="js/fback.js"></script>
</body>
</html>
答案 0 :(得分:0)
在成功执行POST请求后,立即使用GET方法重定向到相同的网址。
因此,您的PHP块(处理POST请求)将如下所示:
<?php
include('session.php');
if(isset($_POST['submit'])){
$fidbak = mysqli_real_escape_string($db,$_POST['fidbak']);
$sql = "INSERT INTO tblfeedback VALUES ('$user_check',
'$FirstName $MiddleName $LastName', '$fidbak')";
$result = mysqli_query($db,$sql) or die(mysql_error());
header('Location: ' . $_SERVER['PHP_SELF'], true, 307);
}
?>