Dismiss Notice
Welcome to Our Community
Wanting to join the rest of our members? Feel free to sign up today.

php file value problem

Discussion in 'Programming' started by komrad, Oct 14, 2008.

  1. komrad

    komrad New Member Webmaster

    Hello all,

    I'm a learning php this year but i encounters some problems.

    One of them is about php value. The problem is how do i do to prevent a php file from resending the same values into the database whenever the page is refreshed?

    Anyone help?


  2. BlueBoden

    BlueBoden New Member Webmaster

    You should redirect users when their post was successful, that way you avoid all such duplicate posts.

    Using the post method, posting to a script which will either throw out an error, or redirect the user to the page they where viewing.

    Hitting refresh won't repost their message since they where redirected, and hitting the back button will only bring them back to the same page, that is the page they where viewing and posting from.

    You can do this redirect using the header function of PHP, it would of cause be a good idea to show a success message on the page you redirect them to, especially if you require some sort of validation of their post, otherwise they might think their post where lost and try to submit it again.
    Last edited by a moderator: Nov 10, 2008
    2 people like this.
  3. Rebentrost

    Rebentrost New Member Webmaster

    To prevent this you could add a captcha image, but it really depends on your website.

    A good php programmer would have the script search for existing records before adding a new one.
  4. BlueBoden

    BlueBoden New Member Webmaster

    Not necessarily. Usually autoincrements is used on one of the columns in the database, this should avoid exact duplicates.

    Extra checking for user errors that almost never occur, is just a waste of coding effort. It would be just as good to add a delete feature which is likely to be required anyway. :botles:

Featured Resources (View All)

Share This Page