how can we deal with the database entry on the page refreshment

Collapse
X
 
  • Time
  • Show
Clear All
new posts
  • anubhavjha
    New Member
    • Jul 2008
    • 22

    how can we deal with the database entry on the page refreshment

    Hi I am having a web form which on submit is entering the data in the database.

    Now if the page is refreshed the data is entered in the database again. can any one help me on how to get it fixed..

    i tried to check with the javascript and html page refreshes. but i am not getting on how to work with it.

    any help is appreciated
  • realin
    Contributor
    • Feb 2007
    • 254

    #2
    Originally posted by anubhavjha
    Hi I am having a web form which on submit is entering the data in the database.

    Now if the page is refreshed the data is entered in the database again. can any one help me on how to get it fixed..

    i tried to check with the javascript and html page refreshes. but i am not getting on how to work with it.

    any help is appreciated
    hiya anubhavjha,

    it is a common problem among new programmers. You have to make ur script in step wise. read below:

    suppose data.php is your php file which submits entries to database, now when it submits your script should land onto an html page, where you have a javascript function which redirects to the actual page which you want to display after submission of data. This is very commonly seen on forums, when u just login and it says, wait for 5 seconds or click here if the browser doesn't redirects.

    hope this helps
    cheers !!

    Comment

    • developing
      New Member
      • Mar 2007
      • 110

      #3
      not sure what's the context of your needs but you can have an 'if' statement that checks the database for exisitng data before updating it.

      or

      you can have a session variable that is set to true when the database is updated. in your script, check the value of the variable. If it is false, update database. If it is true, don't update

      Comment

      • Markus
        Recognized Expert Expert
        • Jun 2007
        • 6092

        #4
        You might unset() the post data once the DB is updated, then move the location to a new page.

        Comment

        • pbmods
          Recognized Expert Expert
          • Apr 2007
          • 5821

          #5
          Heya, anubhavjha.

          Once you have finished saving the new record, use a Location: header to redirect the browser (http://php.net/header).

          Comment

          • dlite922
            Recognized Expert Top Contributor
            • Dec 2007
            • 1586

            #6
            LOL @ refreshment

            /sorry, just had to

            Dan

            Comment

            • anubhavjha
              New Member
              • Jul 2008
              • 22

              #7
              Hi dear all,

              Thank you for the valuable reply.

              I have tried doing a header redirection but when i do that the variables that I have used in the $_session seems to be lost.

              Also if we use the javascript function as when to redirect the page if it gets refreshed. can we use the post variables of the first page. I mean if let us say that there is a page1.php,page2 .html and page3.php

              page3.php will be loaded only if the page2 is not refreshed. will the values of page 1 be captured in the page3.

              If you can give any more inputs on the page refreshment I will be thankful,

              Regards,

              Comment

              • anubhavjha
                New Member
                • Jul 2008
                • 22

                #8
                Originally posted by realin
                hiya anubhavjha,

                it is a common problem among new programmers. You have to make ur script in step wise. read below:

                suppose data.php is your php file which submits entries to database, now when it submits your script should land onto an html page, where you have a javascript function which redirects to the actual page which you want to display after submission of data. This is very commonly seen on forums, when u just login and it says, wait for 5 seconds or click here if the browser doesn't redirects.

                hope this helps
                cheers !!
                I am not able to understand this. sorry very much to say this but i am a learner in php now.

                Comment

                • realin
                  Contributor
                  • Feb 2007
                  • 254

                  #9
                  mate this one is simple..
                  say if you have page.php where u are manipulating the submitted values, then on page. php

                  [PHP]
                  /* here is the code where you need to write data manipulation or whatver u want
                  *
                  *
                  *
                  */

                  //then after the data is submitted or you are done with what u wanted you can do

                  unset($_POST);
                  //or you can redirect using

                  header("Locatio n:http://to-a-new-location.com");
                  [/PHP]

                  the above should do the trick.. i suppose.
                  any probs let me know

                  Comment

                  • Markus
                    Recognized Expert Expert
                    • Jun 2007
                    • 6092

                    #10
                    You could simply check if the data already exists in the database.

                    Comment

                    Working...