PHP form

Discussion in 'PHP' started by dean5000v, May 9, 2008.

  1. #1
    ok ive done a simple form which posts to
    <?php echo $_SERVER['PHP_SELF'];?>">

    ok when the page gets refreshed after the submit button has been pressed it then resends the data again, how can i stop it from resending the data once the page is resent ??
     
    dean5000v, May 9, 2008 IP
  2. Amilo

    Amilo Peon

    Messages:
    624
    Likes Received:
    18
    Best Answers:
    0
    Trophy Points:
    0
    #2
    Have a look here and see if it helps you.
     
    Amilo, May 9, 2008 IP
  3. dean5000v

    dean5000v Peon

    Messages:
    201
    Likes Received:
    0
    Best Answers:
    0
    Trophy Points:
    0
    #3
    ermm didnt see anything in there that wld help, i just wnt it so if the page is refreshed the data doesnt get resent.
     
    dean5000v, May 9, 2008 IP
  4. blueparukia

    blueparukia Well-Known Member

    Messages:
    1,564
    Likes Received:
    71
    Best Answers:
    7
    Trophy Points:
    160
    #4
    So the data is from the form? In the form, add a hidden input:

    
    <input type="hidden" name="dataResend" />
    
    Code (markup):
    For PHP

    
    <?
    if{!ISSET($_POST['dataResend'])){
    
    //Add code here for when the page is refreshed
    
    }
    else{
    
    //Add Code here for when the form is sent.
    //Refresh the page, clearing all data:
    header("Location: ".$_SERVER['PHP_SELF']."");
    
    }
    ?>
    
    PHP:
     
    blueparukia, May 9, 2008 IP
  5. tamilsoft

    tamilsoft Banned

    Messages:
    1,155
    Likes Received:
    78
    Best Answers:
    0
    Trophy Points:
    0
    #5
    Check with this code:

    <?php
    if(isset($_POST['resend']) && $_POST['resend'] == $_COOKIE['resendvalue'])
    {
    echo 'do insert';
    setcookie('resendvalue','',time()-1000,'/');
    }
    $resendval = time();
    setcookie('resendvalue',$resendval,time()+1000,'/');
    ?>
    PHP:
    
    <form method="post">
    <input type="text" name="mytest">
    <input type="submit" value="ok">
    <input type="hidden" name="resend" value="<?php echo $resendval;?>">
    </form>
    HTML:
     
    tamilsoft, May 9, 2008 IP