Skip to content
  • Categories
  • Recent
  • Tags
  • Popular
  • World
  • Users
  • Groups
Skins
  • Light
  • Cerulean
  • Cosmo
  • Flatly
  • Journal
  • Litera
  • Lumen
  • Lux
  • Materia
  • Minty
  • Morph
  • Pulse
  • Sandstone
  • Simplex
  • Sketchy
  • Spacelab
  • United
  • Yeti
  • Zephyr
  • Dark
  • Cyborg
  • Darkly
  • Quartz
  • Slate
  • Solar
  • Superhero
  • Vapor

  • Default (No Skin)
  • No Skin
Collapse
Code Project
  1. Home
  2. Web Development
  3. Linux, Apache, MySQL, PHP
  4. PHP/SQL -> Duplicate data on Insert when Page is refreshed

PHP/SQL -> Duplicate data on Insert when Page is refreshed

Scheduled Pinned Locked Moved Linux, Apache, MySQL, PHP
databasephphelp
4 Posts 4 Posters 0 Views 1 Watching
  • Oldest to Newest
  • Newest to Oldest
  • Most Votes
Reply
  • Reply as topic
Log in to reply
This topic has been deleted. Only users with topic management privileges can see it.
  • L Offline
    L Offline
    lgmanuel
    wrote on last edited by
    #1

    Hi guys., am having with duplicate entry on the DB when the Page is refreshed.. any solution please,. what am trying to do is when the data is added, the portion of the page loads, not the whole page, am using AJAX to load potion of the page.. help guys, thanks..

    L C J 3 Replies Last reply
    0
    • L lgmanuel

      Hi guys., am having with duplicate entry on the DB when the Page is refreshed.. any solution please,. what am trying to do is when the data is added, the portion of the page loads, not the whole page, am using AJAX to load potion of the page.. help guys, thanks..

      L Offline
      L Offline
      Lost User
      wrote on last edited by
      #2

      You need to check for duplication of data before inserting it into database for all values you are inserting. HTH

      Jinal Desai - LIVE Experience is mother of sage....

      1 Reply Last reply
      0
      • L lgmanuel

        Hi guys., am having with duplicate entry on the DB when the Page is refreshed.. any solution please,. what am trying to do is when the data is added, the portion of the page loads, not the whole page, am using AJAX to load potion of the page.. help guys, thanks..

        C Offline
        C Offline
        cjoki
        wrote on last edited by
        #3

        A refresh will resubmit $_POST variables, that if you are using them in your page logic, means the logic will repeat. These values are stored on the users browser so using unset to clear the post variable will do you no good, you need to do 2 things the first is as the other poster says, make certain the information does not already exist. The second is when the data is processed send the user to a specific URL. This will keep the user from refreshing the page and having post vars repeated. On a side note if you are echoing any information before you redirect the user, they will get a error message (headers already sent or some such). You can fix this with eith redirect by using javascript or you can redign your code to put all the echo'd information into a variable and echo that just after you redirection code.

        1 Reply Last reply
        0
        • L lgmanuel

          Hi guys., am having with duplicate entry on the DB when the Page is refreshed.. any solution please,. what am trying to do is when the data is added, the portion of the page loads, not the whole page, am using AJAX to load potion of the page.. help guys, thanks..

          J Offline
          J Offline
          Jayapal Chandran
          wrote on last edited by
          #4

          I assume you are using an ajax framework which uses iframe to submit your form. In that case you are doing a normal refresh like you press F5. Or if you say that you are using javascript to reload the page like window.location.reload() then you will face that problem whether you are using F5 or reload using javascript. whatever. use window.location.href = window.location.href. this is like assigning a string to as the new url instead of meaning to the browser as reload. so the browser will load the page as a new request instead of page refresh. so we are reassigning a new(same) url (requesting the browser to load that page) instead of requesting the browser to reload the page. so the only difference here is loading a page and reloading a page. To load a page use window.location.href = window.location.href (new request) To reload a page use window.location.reload(). (refresh the same) I suppose that your problem lies within this. If you are not using ajax then use the redirect option in php to the same controller(page) to change the last loaded url. for example if you are posting your form data to a page called post.php in that after processing the database operation redirect to again the same post.php. by doing so you are changing the last request as a get request. and after that when you refresh the browser will issue a get request and not the previous post request because it will do a reload only with the last request. DO YOU NEED A SAMPLE CODE? IF THIS DID NOT SOLVE YOUR PROBLEM THEN USE INSERT IGNORE INTO table (field1,field2) VALUES(1,2); Better i should blog this answer with more possible combination. :-\

          Today's Beautiful Moments are Tomorrow's Beautiful Memories

          1 Reply Last reply
          0
          Reply
          • Reply as topic
          Log in to reply
          • Oldest to Newest
          • Newest to Oldest
          • Most Votes


          • Login

          • Don't have an account? Register

          • Login or register to search.
          • First post
            Last post
          0
          • Categories
          • Recent
          • Tags
          • Popular
          • World
          • Users
          • Groups