stop inserting data in the database when refreshing the page












8














I am looking for a way to stop inserting or sending data in the database when refreshing the page.



here is my code:



user_details_page.php



<form action="confirm_page.php" method="post" >
User Name:
<input type="text" name="username" >
User Email
<input type="text" name="useremail" >
Password:
<input type="text" name="password" >
<input type="submit" name="submit" >
</form>




confirm_page.php



if (isset($_POST['submit'])) 
{
$user= $_POST['username'];
$email = $_POST['useremail'];
$pass= $_POST['password'];

mysql_query("INSERT INTO table (username, useremail, email) VALUES ('$username','$useremail','$email');

}


so the problem everytime I refresh the confirm page.php the data is sent to the database. how to stop this?










share|improve this question






















  • Are you manually using the browser's refresh/reload or do you click on a refresh button/link on the webpage?
    – The Debi
    Aug 7 '13 at 23:50










  • @The Debi, I mean the refresh button on the browser
    – Mj Jam
    Aug 8 '13 at 0:26










  • @nnichols, I did the validation and I put a specific part of the code to fix the problem
    – Mj Jam
    Aug 8 '13 at 0:29
















8














I am looking for a way to stop inserting or sending data in the database when refreshing the page.



here is my code:



user_details_page.php



<form action="confirm_page.php" method="post" >
User Name:
<input type="text" name="username" >
User Email
<input type="text" name="useremail" >
Password:
<input type="text" name="password" >
<input type="submit" name="submit" >
</form>




confirm_page.php



if (isset($_POST['submit'])) 
{
$user= $_POST['username'];
$email = $_POST['useremail'];
$pass= $_POST['password'];

mysql_query("INSERT INTO table (username, useremail, email) VALUES ('$username','$useremail','$email');

}


so the problem everytime I refresh the confirm page.php the data is sent to the database. how to stop this?










share|improve this question






















  • Are you manually using the browser's refresh/reload or do you click on a refresh button/link on the webpage?
    – The Debi
    Aug 7 '13 at 23:50










  • @The Debi, I mean the refresh button on the browser
    – Mj Jam
    Aug 8 '13 at 0:26










  • @nnichols, I did the validation and I put a specific part of the code to fix the problem
    – Mj Jam
    Aug 8 '13 at 0:29














8












8








8


3





I am looking for a way to stop inserting or sending data in the database when refreshing the page.



here is my code:



user_details_page.php



<form action="confirm_page.php" method="post" >
User Name:
<input type="text" name="username" >
User Email
<input type="text" name="useremail" >
Password:
<input type="text" name="password" >
<input type="submit" name="submit" >
</form>




confirm_page.php



if (isset($_POST['submit'])) 
{
$user= $_POST['username'];
$email = $_POST['useremail'];
$pass= $_POST['password'];

mysql_query("INSERT INTO table (username, useremail, email) VALUES ('$username','$useremail','$email');

}


so the problem everytime I refresh the confirm page.php the data is sent to the database. how to stop this?










share|improve this question













I am looking for a way to stop inserting or sending data in the database when refreshing the page.



here is my code:



user_details_page.php



<form action="confirm_page.php" method="post" >
User Name:
<input type="text" name="username" >
User Email
<input type="text" name="useremail" >
Password:
<input type="text" name="password" >
<input type="submit" name="submit" >
</form>




confirm_page.php



if (isset($_POST['submit'])) 
{
$user= $_POST['username'];
$email = $_POST['useremail'];
$pass= $_POST['password'];

mysql_query("INSERT INTO table (username, useremail, email) VALUES ('$username','$useremail','$email');

}


so the problem everytime I refresh the confirm page.php the data is sent to the database. how to stop this?







php mysql database load refresh






share|improve this question













share|improve this question











share|improve this question




share|improve this question










asked Aug 7 '13 at 23:46









Mj Jam

833412




833412












  • Are you manually using the browser's refresh/reload or do you click on a refresh button/link on the webpage?
    – The Debi
    Aug 7 '13 at 23:50










  • @The Debi, I mean the refresh button on the browser
    – Mj Jam
    Aug 8 '13 at 0:26










  • @nnichols, I did the validation and I put a specific part of the code to fix the problem
    – Mj Jam
    Aug 8 '13 at 0:29


















  • Are you manually using the browser's refresh/reload or do you click on a refresh button/link on the webpage?
    – The Debi
    Aug 7 '13 at 23:50










  • @The Debi, I mean the refresh button on the browser
    – Mj Jam
    Aug 8 '13 at 0:26










  • @nnichols, I did the validation and I put a specific part of the code to fix the problem
    – Mj Jam
    Aug 8 '13 at 0:29
















Are you manually using the browser's refresh/reload or do you click on a refresh button/link on the webpage?
– The Debi
Aug 7 '13 at 23:50




Are you manually using the browser's refresh/reload or do you click on a refresh button/link on the webpage?
– The Debi
Aug 7 '13 at 23:50












@The Debi, I mean the refresh button on the browser
– Mj Jam
Aug 8 '13 at 0:26




@The Debi, I mean the refresh button on the browser
– Mj Jam
Aug 8 '13 at 0:26












@nnichols, I did the validation and I put a specific part of the code to fix the problem
– Mj Jam
Aug 8 '13 at 0:29




@nnichols, I did the validation and I put a specific part of the code to fix the problem
– Mj Jam
Aug 8 '13 at 0:29












9 Answers
9






active

oldest

votes


















16














Header the user to a new page :



if (isset($_POST['submit'])) 
{
$user= $_POST['username'];
$email = $_POST['useremail'];
$pass= $_POST['password'];

mysql_query("INSERT INTO table (username, useremail, email) VALUES(`$username','$useremail','$email')");

}
//best outside the if statement so user isn't stuck on a white blank page.
header("location: landing_page.php");
exit;


By doing this the user who refreshes will be refreshing landing_page.php which means it won't do the insert twice.



best advice: do a check to see if user exists first if so don't insert!






share|improve this answer





























    1














    What is going on here is that when you refresh page, the form is submitted twice.



    To prevent this, you can use sessions:



    session_start();

    if( $_SESSION['submit'] == $_POST['submit'] &&
    isset($_SESSION['submit'])){
    // user double submitted
    }
    else {
    // user submitted once
    $_SESSION['submit'] = $_POST['submit'];
    }





    share|improve this answer





























      0














      Once an insert or update is done in your code you always need to redirect to another page.



      See here on how to do that: How to make a redirect in PHP?



      (You want to use a PHP redirect, not a Javascript or HTML one, because you obviously really need this to work.)



      The confirm page should be what you redirect to after the update, not what does the insert.






      share|improve this answer























      • Not true - that can work but there's lots of times where you need to stay on same page
        – anoldermark
        Feb 3 '17 at 16:06










      • @mark If want to stay on the same page either use Ajax or redirect back to the same page with different parameters, but if you did a normal HTML submit and don't redirect and someone refreshes the page then the same parameters are resent and you get a double submit of that data.
        – developerwjk
        Feb 8 '17 at 20:52





















      0














      confirm_page.php:



      if (isset($_POST['submit'])) 
      {
      $user= $_POST['username'];
      $email = $_POST['useremail'];
      $pass= $_POST['password'];

      mysql_query("INSERT INTO table (username, useremail, email) VALUES ('$username','$useremail','$email')"); // <-- missing endquote and bracket here

      header('Location: somewhere_else.php');
      exit;
      }





      share|improve this answer





























        0














        The best way to prevent that is to add header('Location: filename') after your query. Thus in your case,



        if (isset($_POST['submit'])) 
        {
        $user= $_POST['username'];
        $email = $_POST['useremail'];
        $pass= $_POST['password'];

        mysql_query("INSERT INTO table (username, useremail, email) VALUES ('$username','$useremail','$email');
        //must be inside the condition to prevent too many redirects
        header('Location: user_details_page.php');
        }





        share|improve this answer































          0














          i have this solution by using session



          <?php session_start();
          if(isset($_POST[$_SESSION[a][count($_SESSION[a])-1]])){
          echo "somthing....";
          unset($_SESSION[a]);
          }
          else{
          echo '<form method="post">';
          $_SESSION["a"]=array();
          $_SESSION["a"][0]="a".rand(1,100);
          echo '<input name="'.$_SESSION["a"][0].'"><br>';
          $_SESSION["a"][1]="a".rand(1,100);
          echo '<input name="'.$_SESSION["a"][1].'"><br>';
          $_SESSION["a"][2]="a".rand(1,100);
          echo '<input name="'.$_SESSION["a"][2].'"><br>';
          $_SESSION["a"][3]="a".rand(1,100);
          echo '<input type="submit" name="'.$_SESSION["a"][3].'" value="submit"><br>';
          echo '</form>';
          }
          ?>





          share|improve this answer





























            0














            We can stop it without redirect , best way to use PHP $_SESSION like this :



            if($_SERVER['REQUEST_METHOD'] == 'POST' && empty($_SESSION['form_submit']) )
            {
            extract($_POST);
            $sql=""INSERT INTO table (username, useremail, email) VALUES('$username','$useremail','$email')";
            $_SESSION['form_submit']='true';
            }
            else
            {
            $_SESSION['form_submit']='NULL';
            }





            share|improve this answer





























              0














              The fast way is to redirect the page to it's current location:



              if (isset($_POST['submit'])) 
              {
              //do somthing
              header("Location: $current_url");
              }





              share|improve this answer





























                -1














                if($_POST(submit)
                {
                //database insertion query
                // if successful insertion
                {
                echo"<script language='javascript'>alert('successfully inserted')</script>";
                echo"<script>document.location='your_page.php';</script>;
                }
                }





                share|improve this answer




















                  protected by Community May 20 '18 at 19:46



                  Thank you for your interest in this question.
                  Because it has attracted low-quality or spam answers that had to be removed, posting an answer now requires 10 reputation on this site (the association bonus does not count).



                  Would you like to answer one of these unanswered questions instead?














                  9 Answers
                  9






                  active

                  oldest

                  votes








                  9 Answers
                  9






                  active

                  oldest

                  votes









                  active

                  oldest

                  votes






                  active

                  oldest

                  votes









                  16














                  Header the user to a new page :



                  if (isset($_POST['submit'])) 
                  {
                  $user= $_POST['username'];
                  $email = $_POST['useremail'];
                  $pass= $_POST['password'];

                  mysql_query("INSERT INTO table (username, useremail, email) VALUES(`$username','$useremail','$email')");

                  }
                  //best outside the if statement so user isn't stuck on a white blank page.
                  header("location: landing_page.php");
                  exit;


                  By doing this the user who refreshes will be refreshing landing_page.php which means it won't do the insert twice.



                  best advice: do a check to see if user exists first if so don't insert!






                  share|improve this answer


























                    16














                    Header the user to a new page :



                    if (isset($_POST['submit'])) 
                    {
                    $user= $_POST['username'];
                    $email = $_POST['useremail'];
                    $pass= $_POST['password'];

                    mysql_query("INSERT INTO table (username, useremail, email) VALUES(`$username','$useremail','$email')");

                    }
                    //best outside the if statement so user isn't stuck on a white blank page.
                    header("location: landing_page.php");
                    exit;


                    By doing this the user who refreshes will be refreshing landing_page.php which means it won't do the insert twice.



                    best advice: do a check to see if user exists first if so don't insert!






                    share|improve this answer
























                      16












                      16








                      16






                      Header the user to a new page :



                      if (isset($_POST['submit'])) 
                      {
                      $user= $_POST['username'];
                      $email = $_POST['useremail'];
                      $pass= $_POST['password'];

                      mysql_query("INSERT INTO table (username, useremail, email) VALUES(`$username','$useremail','$email')");

                      }
                      //best outside the if statement so user isn't stuck on a white blank page.
                      header("location: landing_page.php");
                      exit;


                      By doing this the user who refreshes will be refreshing landing_page.php which means it won't do the insert twice.



                      best advice: do a check to see if user exists first if so don't insert!






                      share|improve this answer












                      Header the user to a new page :



                      if (isset($_POST['submit'])) 
                      {
                      $user= $_POST['username'];
                      $email = $_POST['useremail'];
                      $pass= $_POST['password'];

                      mysql_query("INSERT INTO table (username, useremail, email) VALUES(`$username','$useremail','$email')");

                      }
                      //best outside the if statement so user isn't stuck on a white blank page.
                      header("location: landing_page.php");
                      exit;


                      By doing this the user who refreshes will be refreshing landing_page.php which means it won't do the insert twice.



                      best advice: do a check to see if user exists first if so don't insert!







                      share|improve this answer












                      share|improve this answer



                      share|improve this answer










                      answered Aug 7 '13 at 23:51









                      Sir

                      4,608951115




                      4,608951115

























                          1














                          What is going on here is that when you refresh page, the form is submitted twice.



                          To prevent this, you can use sessions:



                          session_start();

                          if( $_SESSION['submit'] == $_POST['submit'] &&
                          isset($_SESSION['submit'])){
                          // user double submitted
                          }
                          else {
                          // user submitted once
                          $_SESSION['submit'] = $_POST['submit'];
                          }





                          share|improve this answer


























                            1














                            What is going on here is that when you refresh page, the form is submitted twice.



                            To prevent this, you can use sessions:



                            session_start();

                            if( $_SESSION['submit'] == $_POST['submit'] &&
                            isset($_SESSION['submit'])){
                            // user double submitted
                            }
                            else {
                            // user submitted once
                            $_SESSION['submit'] = $_POST['submit'];
                            }





                            share|improve this answer
























                              1












                              1








                              1






                              What is going on here is that when you refresh page, the form is submitted twice.



                              To prevent this, you can use sessions:



                              session_start();

                              if( $_SESSION['submit'] == $_POST['submit'] &&
                              isset($_SESSION['submit'])){
                              // user double submitted
                              }
                              else {
                              // user submitted once
                              $_SESSION['submit'] = $_POST['submit'];
                              }





                              share|improve this answer












                              What is going on here is that when you refresh page, the form is submitted twice.



                              To prevent this, you can use sessions:



                              session_start();

                              if( $_SESSION['submit'] == $_POST['submit'] &&
                              isset($_SESSION['submit'])){
                              // user double submitted
                              }
                              else {
                              // user submitted once
                              $_SESSION['submit'] = $_POST['submit'];
                              }






                              share|improve this answer












                              share|improve this answer



                              share|improve this answer










                              answered Aug 7 '13 at 23:54









                              jh314

                              20.1k124465




                              20.1k124465























                                  0














                                  Once an insert or update is done in your code you always need to redirect to another page.



                                  See here on how to do that: How to make a redirect in PHP?



                                  (You want to use a PHP redirect, not a Javascript or HTML one, because you obviously really need this to work.)



                                  The confirm page should be what you redirect to after the update, not what does the insert.






                                  share|improve this answer























                                  • Not true - that can work but there's lots of times where you need to stay on same page
                                    – anoldermark
                                    Feb 3 '17 at 16:06










                                  • @mark If want to stay on the same page either use Ajax or redirect back to the same page with different parameters, but if you did a normal HTML submit and don't redirect and someone refreshes the page then the same parameters are resent and you get a double submit of that data.
                                    – developerwjk
                                    Feb 8 '17 at 20:52


















                                  0














                                  Once an insert or update is done in your code you always need to redirect to another page.



                                  See here on how to do that: How to make a redirect in PHP?



                                  (You want to use a PHP redirect, not a Javascript or HTML one, because you obviously really need this to work.)



                                  The confirm page should be what you redirect to after the update, not what does the insert.






                                  share|improve this answer























                                  • Not true - that can work but there's lots of times where you need to stay on same page
                                    – anoldermark
                                    Feb 3 '17 at 16:06










                                  • @mark If want to stay on the same page either use Ajax or redirect back to the same page with different parameters, but if you did a normal HTML submit and don't redirect and someone refreshes the page then the same parameters are resent and you get a double submit of that data.
                                    – developerwjk
                                    Feb 8 '17 at 20:52
















                                  0












                                  0








                                  0






                                  Once an insert or update is done in your code you always need to redirect to another page.



                                  See here on how to do that: How to make a redirect in PHP?



                                  (You want to use a PHP redirect, not a Javascript or HTML one, because you obviously really need this to work.)



                                  The confirm page should be what you redirect to after the update, not what does the insert.






                                  share|improve this answer














                                  Once an insert or update is done in your code you always need to redirect to another page.



                                  See here on how to do that: How to make a redirect in PHP?



                                  (You want to use a PHP redirect, not a Javascript or HTML one, because you obviously really need this to work.)



                                  The confirm page should be what you redirect to after the update, not what does the insert.







                                  share|improve this answer














                                  share|improve this answer



                                  share|improve this answer








                                  edited May 23 '17 at 12:17









                                  Community

                                  11




                                  11










                                  answered Aug 7 '13 at 23:49









                                  developerwjk

                                  7,8262930




                                  7,8262930












                                  • Not true - that can work but there's lots of times where you need to stay on same page
                                    – anoldermark
                                    Feb 3 '17 at 16:06










                                  • @mark If want to stay on the same page either use Ajax or redirect back to the same page with different parameters, but if you did a normal HTML submit and don't redirect and someone refreshes the page then the same parameters are resent and you get a double submit of that data.
                                    – developerwjk
                                    Feb 8 '17 at 20:52




















                                  • Not true - that can work but there's lots of times where you need to stay on same page
                                    – anoldermark
                                    Feb 3 '17 at 16:06










                                  • @mark If want to stay on the same page either use Ajax or redirect back to the same page with different parameters, but if you did a normal HTML submit and don't redirect and someone refreshes the page then the same parameters are resent and you get a double submit of that data.
                                    – developerwjk
                                    Feb 8 '17 at 20:52


















                                  Not true - that can work but there's lots of times where you need to stay on same page
                                  – anoldermark
                                  Feb 3 '17 at 16:06




                                  Not true - that can work but there's lots of times where you need to stay on same page
                                  – anoldermark
                                  Feb 3 '17 at 16:06












                                  @mark If want to stay on the same page either use Ajax or redirect back to the same page with different parameters, but if you did a normal HTML submit and don't redirect and someone refreshes the page then the same parameters are resent and you get a double submit of that data.
                                  – developerwjk
                                  Feb 8 '17 at 20:52






                                  @mark If want to stay on the same page either use Ajax or redirect back to the same page with different parameters, but if you did a normal HTML submit and don't redirect and someone refreshes the page then the same parameters are resent and you get a double submit of that data.
                                  – developerwjk
                                  Feb 8 '17 at 20:52













                                  0














                                  confirm_page.php:



                                  if (isset($_POST['submit'])) 
                                  {
                                  $user= $_POST['username'];
                                  $email = $_POST['useremail'];
                                  $pass= $_POST['password'];

                                  mysql_query("INSERT INTO table (username, useremail, email) VALUES ('$username','$useremail','$email')"); // <-- missing endquote and bracket here

                                  header('Location: somewhere_else.php');
                                  exit;
                                  }





                                  share|improve this answer


























                                    0














                                    confirm_page.php:



                                    if (isset($_POST['submit'])) 
                                    {
                                    $user= $_POST['username'];
                                    $email = $_POST['useremail'];
                                    $pass= $_POST['password'];

                                    mysql_query("INSERT INTO table (username, useremail, email) VALUES ('$username','$useremail','$email')"); // <-- missing endquote and bracket here

                                    header('Location: somewhere_else.php');
                                    exit;
                                    }





                                    share|improve this answer
























                                      0












                                      0








                                      0






                                      confirm_page.php:



                                      if (isset($_POST['submit'])) 
                                      {
                                      $user= $_POST['username'];
                                      $email = $_POST['useremail'];
                                      $pass= $_POST['password'];

                                      mysql_query("INSERT INTO table (username, useremail, email) VALUES ('$username','$useremail','$email')"); // <-- missing endquote and bracket here

                                      header('Location: somewhere_else.php');
                                      exit;
                                      }





                                      share|improve this answer












                                      confirm_page.php:



                                      if (isset($_POST['submit'])) 
                                      {
                                      $user= $_POST['username'];
                                      $email = $_POST['useremail'];
                                      $pass= $_POST['password'];

                                      mysql_query("INSERT INTO table (username, useremail, email) VALUES ('$username','$useremail','$email')"); // <-- missing endquote and bracket here

                                      header('Location: somewhere_else.php');
                                      exit;
                                      }






                                      share|improve this answer












                                      share|improve this answer



                                      share|improve this answer










                                      answered Aug 7 '13 at 23:50









                                      Sammitch

                                      19.8k42964




                                      19.8k42964























                                          0














                                          The best way to prevent that is to add header('Location: filename') after your query. Thus in your case,



                                          if (isset($_POST['submit'])) 
                                          {
                                          $user= $_POST['username'];
                                          $email = $_POST['useremail'];
                                          $pass= $_POST['password'];

                                          mysql_query("INSERT INTO table (username, useremail, email) VALUES ('$username','$useremail','$email');
                                          //must be inside the condition to prevent too many redirects
                                          header('Location: user_details_page.php');
                                          }





                                          share|improve this answer




























                                            0














                                            The best way to prevent that is to add header('Location: filename') after your query. Thus in your case,



                                            if (isset($_POST['submit'])) 
                                            {
                                            $user= $_POST['username'];
                                            $email = $_POST['useremail'];
                                            $pass= $_POST['password'];

                                            mysql_query("INSERT INTO table (username, useremail, email) VALUES ('$username','$useremail','$email');
                                            //must be inside the condition to prevent too many redirects
                                            header('Location: user_details_page.php');
                                            }





                                            share|improve this answer


























                                              0












                                              0








                                              0






                                              The best way to prevent that is to add header('Location: filename') after your query. Thus in your case,



                                              if (isset($_POST['submit'])) 
                                              {
                                              $user= $_POST['username'];
                                              $email = $_POST['useremail'];
                                              $pass= $_POST['password'];

                                              mysql_query("INSERT INTO table (username, useremail, email) VALUES ('$username','$useremail','$email');
                                              //must be inside the condition to prevent too many redirects
                                              header('Location: user_details_page.php');
                                              }





                                              share|improve this answer














                                              The best way to prevent that is to add header('Location: filename') after your query. Thus in your case,



                                              if (isset($_POST['submit'])) 
                                              {
                                              $user= $_POST['username'];
                                              $email = $_POST['useremail'];
                                              $pass= $_POST['password'];

                                              mysql_query("INSERT INTO table (username, useremail, email) VALUES ('$username','$useremail','$email');
                                              //must be inside the condition to prevent too many redirects
                                              header('Location: user_details_page.php');
                                              }






                                              share|improve this answer














                                              share|improve this answer



                                              share|improve this answer








                                              edited Aug 8 '13 at 0:18

























                                              answered Aug 7 '13 at 23:50









                                              Kim Barcelona

                                              14




                                              14























                                                  0














                                                  i have this solution by using session



                                                  <?php session_start();
                                                  if(isset($_POST[$_SESSION[a][count($_SESSION[a])-1]])){
                                                  echo "somthing....";
                                                  unset($_SESSION[a]);
                                                  }
                                                  else{
                                                  echo '<form method="post">';
                                                  $_SESSION["a"]=array();
                                                  $_SESSION["a"][0]="a".rand(1,100);
                                                  echo '<input name="'.$_SESSION["a"][0].'"><br>';
                                                  $_SESSION["a"][1]="a".rand(1,100);
                                                  echo '<input name="'.$_SESSION["a"][1].'"><br>';
                                                  $_SESSION["a"][2]="a".rand(1,100);
                                                  echo '<input name="'.$_SESSION["a"][2].'"><br>';
                                                  $_SESSION["a"][3]="a".rand(1,100);
                                                  echo '<input type="submit" name="'.$_SESSION["a"][3].'" value="submit"><br>';
                                                  echo '</form>';
                                                  }
                                                  ?>





                                                  share|improve this answer


























                                                    0














                                                    i have this solution by using session



                                                    <?php session_start();
                                                    if(isset($_POST[$_SESSION[a][count($_SESSION[a])-1]])){
                                                    echo "somthing....";
                                                    unset($_SESSION[a]);
                                                    }
                                                    else{
                                                    echo '<form method="post">';
                                                    $_SESSION["a"]=array();
                                                    $_SESSION["a"][0]="a".rand(1,100);
                                                    echo '<input name="'.$_SESSION["a"][0].'"><br>';
                                                    $_SESSION["a"][1]="a".rand(1,100);
                                                    echo '<input name="'.$_SESSION["a"][1].'"><br>';
                                                    $_SESSION["a"][2]="a".rand(1,100);
                                                    echo '<input name="'.$_SESSION["a"][2].'"><br>';
                                                    $_SESSION["a"][3]="a".rand(1,100);
                                                    echo '<input type="submit" name="'.$_SESSION["a"][3].'" value="submit"><br>';
                                                    echo '</form>';
                                                    }
                                                    ?>





                                                    share|improve this answer
























                                                      0












                                                      0








                                                      0






                                                      i have this solution by using session



                                                      <?php session_start();
                                                      if(isset($_POST[$_SESSION[a][count($_SESSION[a])-1]])){
                                                      echo "somthing....";
                                                      unset($_SESSION[a]);
                                                      }
                                                      else{
                                                      echo '<form method="post">';
                                                      $_SESSION["a"]=array();
                                                      $_SESSION["a"][0]="a".rand(1,100);
                                                      echo '<input name="'.$_SESSION["a"][0].'"><br>';
                                                      $_SESSION["a"][1]="a".rand(1,100);
                                                      echo '<input name="'.$_SESSION["a"][1].'"><br>';
                                                      $_SESSION["a"][2]="a".rand(1,100);
                                                      echo '<input name="'.$_SESSION["a"][2].'"><br>';
                                                      $_SESSION["a"][3]="a".rand(1,100);
                                                      echo '<input type="submit" name="'.$_SESSION["a"][3].'" value="submit"><br>';
                                                      echo '</form>';
                                                      }
                                                      ?>





                                                      share|improve this answer












                                                      i have this solution by using session



                                                      <?php session_start();
                                                      if(isset($_POST[$_SESSION[a][count($_SESSION[a])-1]])){
                                                      echo "somthing....";
                                                      unset($_SESSION[a]);
                                                      }
                                                      else{
                                                      echo '<form method="post">';
                                                      $_SESSION["a"]=array();
                                                      $_SESSION["a"][0]="a".rand(1,100);
                                                      echo '<input name="'.$_SESSION["a"][0].'"><br>';
                                                      $_SESSION["a"][1]="a".rand(1,100);
                                                      echo '<input name="'.$_SESSION["a"][1].'"><br>';
                                                      $_SESSION["a"][2]="a".rand(1,100);
                                                      echo '<input name="'.$_SESSION["a"][2].'"><br>';
                                                      $_SESSION["a"][3]="a".rand(1,100);
                                                      echo '<input type="submit" name="'.$_SESSION["a"][3].'" value="submit"><br>';
                                                      echo '</form>';
                                                      }
                                                      ?>






                                                      share|improve this answer












                                                      share|improve this answer



                                                      share|improve this answer










                                                      answered Aug 26 '13 at 22:30









                                                      hazem

                                                      1325




                                                      1325























                                                          0














                                                          We can stop it without redirect , best way to use PHP $_SESSION like this :



                                                          if($_SERVER['REQUEST_METHOD'] == 'POST' && empty($_SESSION['form_submit']) )
                                                          {
                                                          extract($_POST);
                                                          $sql=""INSERT INTO table (username, useremail, email) VALUES('$username','$useremail','$email')";
                                                          $_SESSION['form_submit']='true';
                                                          }
                                                          else
                                                          {
                                                          $_SESSION['form_submit']='NULL';
                                                          }





                                                          share|improve this answer


























                                                            0














                                                            We can stop it without redirect , best way to use PHP $_SESSION like this :



                                                            if($_SERVER['REQUEST_METHOD'] == 'POST' && empty($_SESSION['form_submit']) )
                                                            {
                                                            extract($_POST);
                                                            $sql=""INSERT INTO table (username, useremail, email) VALUES('$username','$useremail','$email')";
                                                            $_SESSION['form_submit']='true';
                                                            }
                                                            else
                                                            {
                                                            $_SESSION['form_submit']='NULL';
                                                            }





                                                            share|improve this answer
























                                                              0












                                                              0








                                                              0






                                                              We can stop it without redirect , best way to use PHP $_SESSION like this :



                                                              if($_SERVER['REQUEST_METHOD'] == 'POST' && empty($_SESSION['form_submit']) )
                                                              {
                                                              extract($_POST);
                                                              $sql=""INSERT INTO table (username, useremail, email) VALUES('$username','$useremail','$email')";
                                                              $_SESSION['form_submit']='true';
                                                              }
                                                              else
                                                              {
                                                              $_SESSION['form_submit']='NULL';
                                                              }





                                                              share|improve this answer












                                                              We can stop it without redirect , best way to use PHP $_SESSION like this :



                                                              if($_SERVER['REQUEST_METHOD'] == 'POST' && empty($_SESSION['form_submit']) )
                                                              {
                                                              extract($_POST);
                                                              $sql=""INSERT INTO table (username, useremail, email) VALUES('$username','$useremail','$email')";
                                                              $_SESSION['form_submit']='true';
                                                              }
                                                              else
                                                              {
                                                              $_SESSION['form_submit']='NULL';
                                                              }






                                                              share|improve this answer












                                                              share|improve this answer



                                                              share|improve this answer










                                                              answered Nov 20 '15 at 5:13









                                                              Ak Memon

                                                              116




                                                              116























                                                                  0














                                                                  The fast way is to redirect the page to it's current location:



                                                                  if (isset($_POST['submit'])) 
                                                                  {
                                                                  //do somthing
                                                                  header("Location: $current_url");
                                                                  }





                                                                  share|improve this answer


























                                                                    0














                                                                    The fast way is to redirect the page to it's current location:



                                                                    if (isset($_POST['submit'])) 
                                                                    {
                                                                    //do somthing
                                                                    header("Location: $current_url");
                                                                    }





                                                                    share|improve this answer
























                                                                      0












                                                                      0








                                                                      0






                                                                      The fast way is to redirect the page to it's current location:



                                                                      if (isset($_POST['submit'])) 
                                                                      {
                                                                      //do somthing
                                                                      header("Location: $current_url");
                                                                      }





                                                                      share|improve this answer












                                                                      The fast way is to redirect the page to it's current location:



                                                                      if (isset($_POST['submit'])) 
                                                                      {
                                                                      //do somthing
                                                                      header("Location: $current_url");
                                                                      }






                                                                      share|improve this answer












                                                                      share|improve this answer



                                                                      share|improve this answer










                                                                      answered Nov 23 '18 at 15:25









                                                                      Eyal Sooliman

                                                                      9801021




                                                                      9801021























                                                                          -1














                                                                          if($_POST(submit)
                                                                          {
                                                                          //database insertion query
                                                                          // if successful insertion
                                                                          {
                                                                          echo"<script language='javascript'>alert('successfully inserted')</script>";
                                                                          echo"<script>document.location='your_page.php';</script>;
                                                                          }
                                                                          }





                                                                          share|improve this answer


























                                                                            -1














                                                                            if($_POST(submit)
                                                                            {
                                                                            //database insertion query
                                                                            // if successful insertion
                                                                            {
                                                                            echo"<script language='javascript'>alert('successfully inserted')</script>";
                                                                            echo"<script>document.location='your_page.php';</script>;
                                                                            }
                                                                            }





                                                                            share|improve this answer
























                                                                              -1












                                                                              -1








                                                                              -1






                                                                              if($_POST(submit)
                                                                              {
                                                                              //database insertion query
                                                                              // if successful insertion
                                                                              {
                                                                              echo"<script language='javascript'>alert('successfully inserted')</script>";
                                                                              echo"<script>document.location='your_page.php';</script>;
                                                                              }
                                                                              }





                                                                              share|improve this answer












                                                                              if($_POST(submit)
                                                                              {
                                                                              //database insertion query
                                                                              // if successful insertion
                                                                              {
                                                                              echo"<script language='javascript'>alert('successfully inserted')</script>";
                                                                              echo"<script>document.location='your_page.php';</script>;
                                                                              }
                                                                              }






                                                                              share|improve this answer












                                                                              share|improve this answer



                                                                              share|improve this answer










                                                                              answered Apr 25 '18 at 11:44









                                                                              Vishnu S

                                                                              1




                                                                              1

















                                                                                  protected by Community May 20 '18 at 19:46



                                                                                  Thank you for your interest in this question.
                                                                                  Because it has attracted low-quality or spam answers that had to be removed, posting an answer now requires 10 reputation on this site (the association bonus does not count).



                                                                                  Would you like to answer one of these unanswered questions instead?



                                                                                  Popular posts from this blog

                                                                                  Monofisismo

                                                                                  Angular Downloading a file using contenturl with Basic Authentication

                                                                                  Olmecas