Refresh page without running PHP code again

Asked

Viewed 186 times

-3

I want to run a PHP code with the button Submit. The problem is that every time I refresh the page, the code runs again. I used this:

  if (isset($_POST['carregar'])) {
      // pedaço de código...
  }

And the button:

echo "<form method=POST action=#>";
echo "<input type=submit name=carregar value=Carregar>";
echo "</form>";
  • and what’s the problem?

  • Every time I refresh the page, it rerun the code, even without clicking the button.

  • 1

    You have to do as I told you in this answer http://answall.com/a/40158/7210

  • Right and how I identify the name of the button?

  • doings if(isset($_POST['carregar'])) within the if of that answer.

  • if (filter_input(INPUT_SERVER, 'REQUEST_METHOD') === 'POST') { if(isset($_POST['load'])){

  • Still the problem, @akm?

  • If I were you, I’d start thinking about using Ajax

Show 3 more comments

1 answer

0

As stated in this answer just check which button is on:

// Verifica se foi feito um POST
if (filter_input(INPUT_SERVER, 'REQUEST_METHOD') === 'POST')
{
    // Verifica se o foi com o botão carregar
    if(isset($_POST['carregar']))
    {
        //código de inserção após clicar no botão
    }
}
  • I did that, and it keeps running when I update the page.

  • You can’t... I’ve been here testing and it doesn’t happen.

  • It is best to check in the Database if that record already exists. If it exists, it does not add. As in this answer: http://answall.com/a/40169/7210

Browser other questions tagged

You are not signed in. Login or sign up in order to post.