Php how to prevent auto form submit on page load or refresh with F5

stop form submit on refresh php
stop form resubmission on page refresh javascript
php disable refresh
prevent form submit on refresh javascript
how to avoid resending data on refresh in php
prevent form resubmission on refresh jsp
how to prevent page refresh on form submit in codeigniter
confirm form resubmission on refresh javascript

I have the below form and its works fine but when i refresh the page using F5 or however it re submit the form. How can i prevent the auto submission of the form on pageload or refresh. But im using it submit on onchange.

Im using it to update the delivery charge in database only if i will select the different area from dropdown. When i select and different area, it updates the area in Database but when refreshes the page it selects the first row in the list and auto submit the form and update that value in the database.

cart_update_delivery.php

$uid    =   $_POST['area'];

$total  =   mysql_query("
update orders_temp
set area = '".$uid."'
where user_id = 1
");

.........

<script>
function submitForm(){
    var val = document.myform.area.value;
    if(val!=-1){
        document.myform.submit();
    }
}
</script>
<iframe name="q" style="display:none;"></iframe>

<form action="cart_update_delivery.php" method="post" target="q" name="myform">
<select onchange="submitForm();" name="area" data-placeholder="Select area" class="test">
    <optgroup label="0001">
    <option style="" value="1"> A</option>
    <option style="" value="2"> B</option>
    <optgroup label="0002">
    <option style="" value="3"> C</option>
    <option style="" value="4"> D</option>
    </optgroup>
</select>

</form>

You can reload the page after submitting

<script>
    function submitForm(){
        var val = document.myform.area.value;
        if(val!=-1){
            document.myform.submit();
            location.reload(true);
        }
</script>

Php how to prevent auto form submit on page load or refresh with F5 , You can reload the page after submitting <script> function submitForm(){ var val = document.myform.area.value; if(val!=-1){  This is automatically called after the form has been submitted. In this page, session is started. Value is accessed from session and display to the user. To test if whether it prevents duplicate or not, you can simple press f5 to reload the page. Now you must see, it is not asking for confirmation to submit the page.

If I understand you correctly, you should just check whether you have POST data or not. Otherwise you will have your db record rewritten each time your page is loaded.

if (isset($_POST['area'])) 
{
    $uid   = $_POST['area'];
    $total = mysql_query("
    update orders_temp
    set area = '" . $uid . "'
    where user_id = 1
    ");
}

Prevent page from Submit on Refresh in PHP, If the form is already submitted and the user tries to refresh the webpage then the browser will attempt to resubmit the form. If some action does  Prevent page from submit on Refresh in PHP. If the form is already submitted and the user tries to refresh the webpage then the browser will attempt to resubmit the form. If you are allowing the user to fill and submit the form for insert data. In this case, if the user refreshes the page then the data is reinserted on the MySQL database table

In php, you can forward the browser to a fresh page by using a http header after your update. The header must be sent before anything else.

    header('Location: http://www.example.com/');

See PHP: header

How to prevent a form from resubmitting when the page is refreshed , https://www.hows.tech/2019/06/confirm-form-resubmission.html (Keep a variable in the browser code that tells you whether the data has been submitted - if This is how it is done header('location:<?php echo $_SERVER['SELF']?>) or you can Why does my web page become unresponsive for a few seconds on load? Unset Form Data. One way to stop page resubmission on page refresh is to unset the form data after it is submitted so that the variable storing form data becomes empty and wrap up your form processing block of codes to check if the form is empty.

How to stop form resubmission on page refresh, The visitor can reload this page again and again – and nothing will be sent. and it was "complicated" by the fact that I redirect all URLs to a single .php file. The style tag is important otherwise the user may feel like page loaded twice. after the form submission which would stop the form resubmission on page refresh  When this html form is submitted, it will call the javascript function yourJsFunction(), but it won’t reload the page. 2. Use jQuery’s submit event to handle the form submit, add return false; at the end of the submit handle function to prevent the page to reload.

Preventing POST on reloading a form, Once this is done, the user might refresh the page and you will end up with I've appended "?submit=true" to the form action and have included the 18th, 2017 stop insert data in database when refresh page in php. Data Re-submit on Page Refresh Issue in PHP | PHP CRUD app.in this video tutorial you'll learn how to prevent Data Re-submit on Page Refresh. many time while we refresh web page we face Data Re

Data Re-submit on Page Refresh Issue in PHP, In 4.x, if you go to the main bugzilla page and enter a bug # and press reload, Shift+Ctrl+R, Shift+F5, Shift+View>Reload, and Shift+Context Menu>Reload all value of a textarea at http://www.antifa-aktion.de/mozillabug.php try to reload a submitting the form, the server checks the cookie to see when you loaded the  The solution I have seen is related to the session. when you submit a form then you save the values in a session and then empty the values in the form so the page will not resend the values again when it is refreshed. Now I am seeing in your blog that this solution would not be good enough. I would appreciate if you may explain me this problem.

Comments
  • This answer has a SQL injection flaw. Please don't use this.
  • The answer was not about the SQL request itself but about preventing code execution after simple page refresh.
  • I know it is not, but I still felt like mentioning it in case people would copy + paste it to their own code without thinking about the SQL injection possibility.