Javascript 如何防止php表单在刷新时重新提交

Javascript 如何防止php表单在刷新时重新提交,javascript,php,forms,oracle,Javascript,Php,Forms,Oracle,我使用以下代码提交数据库中的字段(使用oracle),但在成功提交表单后,如果我刷新表单,表单将重新提交。我没有在这里使用任何会话 请帮忙 <div class="col-xs-5"> <?php $note=$_REQUEST['note']; $order = "INSERT INTO ec_note (nid, idno, note, flag, ec_date) VALUES (a_seq.next

我使用以下代码提交数据库中的字段(使用oracle),但在成功提交表单后,如果我刷新表单,表单将重新提交。我没有在这里使用任何会话

请帮忙

<div class="col-xs-5">
    <?php
    $note=$_REQUEST['note'];
    $order = "INSERT INTO ec_note (nid, idno, note, flag, ec_date)
            VALUES
            (a_seq.nextval,'$id',
            '$note',1,sysdate)";
        if ($note)
        {
        $result = dbi_query($conn, $order); //order executes
        }
        if($result){
            echo("<div class='alert alert-success alert-dismissible' role='alert'>Your Note has been successfully uploaded
            <button type='button' class='close' data-dismiss='alert' aria-label='Close'><span aria-hidden='true'>&times;</span></button>
            </div>");
            }

    ?>
    <form method="post" action="">
        <textarea class="form-control" name="note" rows="15" placeholder="Maximum 4000 characters "></textarea> <br>
        <button type="submit" name="submit" onSubmit="window.location.reload()" class="btn btn-primary btn-lg btn-block">Add Note</button>
    </form>
</div>


提交如下表格:

<form method="post" action="">
    <textarea class="form-control" name="note" rows="15" placeholder="Maximum 4000 characters "></textarea> <br>
    <button type="submit" name="confirm" class="btn btn-primary btn-lg btn-block">Add Note</button>
</form>
重要。您相信“note”字段是通过邮寄方式到达的,并且不包含任何不好的内容情况可能并非总是如此

因此,要么使用具有准备好的值的查询,要么使用转义来阻止
$\u请求['note']

更好的实施:

if (isset($_POST)
    && array_key_exists('note', $_POST)
) {
    // I am not familiar with dbi_query. I suppose there exists a dbi_escape function?
    $note = YOUR_ESCAPE_FUNCTION($_POST['note'];)
    $order = "INSERT INTO ec_note (nid, idno, note, flag, ec_date)
    VALUES
    (a_seq.nextval,'$id',
    '$note',1,sysdate)";
    $result = dbi_query($conn, $order);

    // CHECK ERRORS AND DISPLAY THE APPROPRIATE RESPONSE

    // If no error, reload the form with a redirect and quit.
    // No output must have been sent to the browser up to now, or
    // this will cause an error.
    die(Header("Location: {$_SERVER['PHP_SELF']}"));
}

在处理提交的数据后执行重定向。在提交之前重新加载也不会调用表单中的任何内容
name=submit
。如果需要测试,请更改它。
if (isset($_POST)
    && array_key_exists('note', $_POST)
) {
    // I am not familiar with dbi_query. I suppose there exists a dbi_escape function?
    $note = YOUR_ESCAPE_FUNCTION($_POST['note'];)
    $order = "INSERT INTO ec_note (nid, idno, note, flag, ec_date)
    VALUES
    (a_seq.nextval,'$id',
    '$note',1,sysdate)";
    $result = dbi_query($conn, $order);

    // CHECK ERRORS AND DISPLAY THE APPROPRIATE RESPONSE

    // If no error, reload the form with a redirect and quit.
    // No output must have been sent to the browser up to now, or
    // this will cause an error.
    die(Header("Location: {$_SERVER['PHP_SELF']}"));
}