避免在刷新页面上提交数据php ['PHP_SELF']

时间:2017-07-17 10:48:47

标签: javascript php

我在表单中使用<?php echo $_SERVER['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;



 ?>

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

1 个答案:

答案 0 :(得分:0)

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

header('Location: /path/to/record');
exit;
相关问题