Warning: file_get_contents(/data/phpspider/zhask/data//catemap/1/php/262.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
Javascript 避免在刷新页面php[';php#u SELF';]上提交数据_Javascript_Php - Fatal编程技术网

Javascript 避免在刷新页面php[';php#u SELF';]上提交数据

Javascript 避免在刷新页面php[';php#u SELF';]上提交数据,javascript,php,Javascript,Php,我在表单中使用。 提交表单后,当我刷新页面时,它会一次又一次地提交表单 请帮助我避免在刷新页面上重新提交表单 以下是PHP代码: if (isset($_POST["patientName"])){ // set the PDO error mode to exception $conn->setAttribute(PDO::ATTR_ERRMODE, PDO::ERRMODE_EXCEPTION); $sql = "INSERT INTO `inpatient`(

我在表单中使用
。 提交表单后,当我刷新页面时,它会一次又一次地提交表单

请帮助我避免在刷新页面上重新提交表单

以下是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;



 ?>
if(isset($\u POST[“patientName”])){
//将PDO错误模式设置为异常
$conn->setAttribute(PDO::ATTR_ERRMODE,PDO::ERRMODE_异常);
$sql=“插入到‘住院病人’('patientId`、'patientName`、'guardianName`、,
`年龄`、`性别`、`mobile`、`address`、`city`、`symptoms`、`reference`、`date`、`time`、`doctorName`、`email`)
值(“$patientId”、“$patientName”、“$guardianName”、“$age”、“$gender”、“$mobile”、“$address”、“$city”、“$symptoms”,
“$reference”、“$date”、“$time”、“$doctorName”、“$email”);
$conn->exec($sql);
}
回声'
x
干得好您已成功输入数据。
';
}
捕获(PDO$e)
{
echo$sql。“
”$e->getMessage(); } $conn=null; ?>

我不想使用标题。我正在同一页打印成功消息

请不要在提交表单后显示回复。只需将其重定向到任何其他页面

header('Location: /path/to/record');
exit;

请不要在提交表格后显示回复。只需将其重定向到任何其他页面

header('Location: /path/to/record');
exit;

显示此页面的代码。可能与浏览器的预期行为重复(在本例中为post请求重新创建了以前的请求),以便在处理post请求后更改需要重定向的内容。@Tajgeer我已更新了代码。请检查。向我们显示此页面的代码。可能与浏览器的预期行为重复(在本例中为post请求重新创建了以前的请求),以更改您在处理post请求后需要重定向的内容。@Tajgeer我已更新代码。请检查。我不想使用页眉,我正在使用echo在同一页上打印成功消息。如果您不想使用页眉,则可以在处理数据后首先取消设置$\u POST变量。对于ex,未设置($邮政);然后在下一步中,使用页眉('Location:'.$\u SERVER['PHP\u SELF'])在同一页面中重定向页面;我不想使用header,我正在使用echo在同一页面上打印成功消息。如果您不想使用header,则可以在处理数据后首先取消设置$\u POST变量。对于ex,未设置($邮政);然后在下一步中,使用页眉('Location:'.$\u SERVER['PHP\u SELF'])在同一页面中重定向页面;