-1

When I insert data and I refresh page It will auto insert old data

I try use header location :

if (!empty($msg_success)) {
        echo '<script type="text/javascript">alert("' . $msg_success . '")</script>';
        header('location:'.$_SERVER['REQUEST_URI']);
        exit();
    }

It's work but It didnt echo alert! before refresh page

How can I echo alert before reload page ? or Is there anyway to prevent insert data when refresh page ?

UPDATE

when I refresh page I've $_POST['submit'] that why my data keep insert when I refresh

Community
  • 1
  • 1
test1321
  • 331
  • 1
  • 8
  • 23
  • You cannot return an HTML response (which would trigger the alert) *and* redirect at the same time via HTTP headers. – deceze Jan 18 '18 at 09:15
  • Possible duplicate of [displaying a message after redirecting the user to another web page](https://stackoverflow.com/questions/12249906/displaying-a-message-after-redirecting-the-user-to-another-web-page) – insertusernamehere Jan 18 '18 at 09:15
  • Possible already answered in [Stackkoverflow How do I reset the value](https://stackoverflow.com/questions/5502305/how-do-i-reset-the-value-of-a-text-input-when-the-page-reloads) – Hiplobbe Jan 18 '18 at 09:18
  • unset all post/get values before header call – NanThiyagan Jan 18 '18 at 09:20

1 Answers1

0

In html you can set an attribute on the input in question to nullify autocomplete.

Set autocomplete attribute to "off"

<input type='text' value='default text' autocomplete='off' />

Hiplobbe
  • 138
  • 6