0

I have an issue.My previous data is inserting again and again at each time of page reload using PHP and MySQL.I am explaining my code below.

 $result = $dbobj->savePincode($newCustomerobj);
    if($result == 1)
    {
        $msg='3';
    }
    else
    {
        $msg='2';
    }
    function messagestatus(st)
{
    switch(st)
    {   
        case 1:
        {
            alert("Data Updated Successfully.");
            <?php header("location:localhost/demo/pincode.php"); ?>
            break;
        } 
        case 2:
        {
            alert("This user id already exist..");
            break;
        } 
        case 3:
        {
            alert("Data Saved Successfully");
            <?php header("location:localhost/demo/pincode.php"); ?>
            break;
        }
        case 4:
        {
            alert("Data deleted Successfully");
            <?php header("location:localhost/demo/pincode.php"); ?>
            break;
        }
    }
}
messagestatus(<?php echo $msg ?>);

Here i am also adding the header but still when user is reloading the page after first time insert again same is inserting.Please help me.

2
  • does code you provided also present in the page "localhost/demo/pincode.php" ? Commented Feb 9, 2016 at 13:35
  • yes,pincode.php page i am running. Commented Feb 9, 2016 at 13:36

1 Answer 1

1

As far I get from your question, you are posting the form data using POST method and after that redirecting user to same page, so your data is getting insert again and again. Do small change as shown below in your code-

<?php header("location:localhost/demo/pincode.php?hash=".time()); ?>

By appending hash parameter with time() value, your browser will consider it as an new url and your form data will not get insert again.

Hope so it will work for your.

Sign up to request clarification or add additional context in comments.

2 Comments

@ PHPExpert : actually what is my problem,Suppose user inserted the data for first time.After inserting when the user is reloading the page again the same data is inserting.
Yes, I considered this scenario and posted solution. Have you tried this solution ? If yes, then me suggest another way.

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.