Post data and refresh page

前端 未结 4 1810
深忆病人
深忆病人 2020-12-29 17:20

I have an edit-form page to edit my website posts. It uses post method to the same page. If the form is compiled correctly shows up a congrats message.

The p

4条回答
  •  感情败类
    2020-12-29 17:32

    The general outline of the PRG pattern is this:

    if ( $_SERVER['REQUEST_METHOD'] == 'POST' )
    {
         /// do your magic
    
         $_SESSION['error'] = "Thanks for your message!";
    
         // this should be the full URL per spec, but "/yourscript.php" will work
         $myurl = ...;
    
         header("Location: $myurl");
         header("HTTP/1.1 303 See Other");
         die("redirecting");
    }
    
    if ( isset($_SESSION['error']) )
    {
         print "The result of your submission: ".$_SESSION['error'];
         unset($_SESSION['error']);
    }
    

提交回复
热议问题