SitePoint Sponsor

User Tag List

Results 1 to 9 of 9
  1. #1
    SitePoint Guru arunkumar's Avatar
    Join Date
    Jan 2005
    Location
    India:Chennai
    Posts
    827
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)

    Question data in inserted into mysql when i click refresh

    Hi..

    I am seleting an item from a page and pass the id of the item to a page where it is added to datase..

    The is is inserting into database but when i click the refresh in the same page the record goes inserting one more time ..

    Is there is any way to avoid this????????
    Where there is a will there is a way
    ArunKumar

  2. #2
    SitePoint Wizard
    Join Date
    Mar 2004
    Posts
    1,647
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    make some uid then first check if the uid exsists then if not store the data...
    example..
    PHP Code:
    $uid substr(md5($_POST["something"]), 7);
    $ret mysql_query("SELECT * FROM table WHERE uid = '$uid'");
    $row mysql_fetch_row($ret);
    if(
    $row[0] > 0) return false;
    else {
    # insert your data

    cheers

  3. #3
    SitePoint Guru arunkumar's Avatar
    Join Date
    Jan 2005
    Location
    India:Chennai
    Posts
    827
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    thank you man...Is this the only way ???
    Where there is a will there is a way
    ArunKumar

  4. #4
    SitePoint Evangelist djdykes's Avatar
    Join Date
    Feb 2005
    Location
    Chester, Cheshire
    Posts
    565
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    redirects are always good... they clear the HTTP headers...

  5. #5
    SitePoint Member
    Join Date
    Dec 2004
    Location
    Sweden
    Posts
    24
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    is there some field in the db that you could set as unique? That way the exact same data won't be added twice at least.

  6. #6
    SitePoint Wizard
    Join Date
    Jan 2004
    Location
    3rd rock from the sun
    Posts
    1,005
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    If its an admin area and you can detect if JS is turned "on", you can stop them resubmitting the form using JS. This provides immediate clues that the form is sent already...

    Otherwise its not a foolproof method.

    Raevel's answer is better if you mean a public form submission.

  7. #7
    SitePoint Guru arunkumar's Avatar
    Join Date
    Jan 2005
    Location
    India:Chennai
    Posts
    827
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    thanks all but i cannt use redirect since i submit the data by a form ..Also should i use database indeed or any other way?
    Where there is a will there is a way
    ArunKumar

  8. #8
    SitePoint Evangelist djdykes's Avatar
    Join Date
    Feb 2005
    Location
    Chester, Cheshire
    Posts
    565
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    redirect after you have processed the form data then... even if you redirect to the script doing the processing it will clear the http headers and stop the same data from being submitted....

  9. #9
    SitePoint Zealot Hulkur's Avatar
    Join Date
    Oct 2001
    Location
    Estonia
    Posts
    141
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    redirecting is the easiest method

    if ($_POST) {
    do the submitting ...
    ...
    header('Location: somewhere');
    exit;
    }
    (2B) or (not 2B) = FF


Bookmarks

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •