我在表单中使用<?php echo $_SERVER['PHP_SELF']; ?>
。 当我刷新页面时提交表单,它一次又一次地提交表单。避免刷新页面上的数据提交php ['PHP_SELF']
请帮助我避免在刷新页面上重新提交表单。
这里是PHP代码:
if (isset($_POST["patientName"])){
// set the PDO error mode to exception
$conn->setAttribute(PDO::ATTR_ERRMODE, PDO::ERRMODE_EXCEPTION);
$sql = "INSERT INTO `inpatient`(`patientId`, `patientName`, `guardianName`,
`age`, `gender`, `mobile`, `address`, `city`, `symptoms`, `reference`, `date`, `time`, `doctorName`, `email`)
VALUES('$patientId', '$patientName', '$guardianName', '$age', '$gender', '$mobile', '$address', '$city', '$symptoms',
'$reference', '$date', '$time', '$doctorName', '$email')";
$conn->exec($sql);
}
echo '
<div style="position:absolute; bottom:0; left:0; z-index:1000; " class="alert alert-icon-left alert-success alert-dismissible fade in mb-2" role="alert">
<button type="button" class="close" data-dismiss="alert" aria-label="Close">
<span aria-hidden="true">x</span>
</button>
<strong>Well done!</strong> You successfully entered the <a href="#" class="alert-link">Patient</a> data.
</div>
';
}
catch(PDOException $e)
{
echo $sql . "<br>" . $e->getMessage();
}
$conn = null;
?>
我不想使用头。我在同一页上打印成功消息
向我们显示此页的代码。 – Tajgeer
可能的重复[最好的方式来避免由于刷新页面提交](https://stackoverflow.com/questions/5690541/best-way-to-avoid-the-submit-due-toa-a-页面刷新) – Ali786
它是浏览器的预期行为(在本例中发布请求时重新创建了以前的请求),以便在处理发布请求后更改您需要重定向的行为。 – Filip