duangaoe9401 2013-04-29 10:25
浏览 53
已采纳

POST / REDIRECT / GET出了什么问题?

I have a website where any visitor can subscribe to receive the newsletter.I encountered the problem of having my resubmitted when everytime when i refreshed the page.I solved it by applying the PRG concept. Now a user never submits the same form twice, i have just one problem : i have designed the form in such a way that when the is succesfully/or fails a message is display under the input fields. Unfortunatly now that i have the PRG concept applied i never get any message displayed . What to do ?

index.php - where i have the divs containing the submit form and the message display

        <div id="newsletter" >
            <form id="abonat" name="abonat" action="formular.php" method="post" onsubmit="return golire()" autocomplete="on"  > 
            <span>Subscribe</span>
            <input type="text" id="nume" name="nume"  placeholder="Name" required />
            <input type="email" id="email" name="email" placeholder="Email" autocomplete="off"  required/> 
            <input type="submit" value="Subscribe" class="button" style="width:26%;float:left;" /> 

            </form>
    </div>  

    <div id="mesaj_newsletter">
        <span><?php if (isset($mesaj)) echo $mesaj; ?> </span>
    </div> 

formular.php - where the validation takes place,and the message is decided

include('conect.php');    
function validEmail($email){
    //code that verifies if it is a valid email adress
}

if( (isset($_POST['email']))&&(isset($_POST['nume'])) ){
    $nume=mysql_real_escape_string($_POST['nume']);
    $email=mysql_real_escape_string($_POST['email']);
    $z=1;
    if(validEmail($email)==TRUE){
        $result=mysql_query("SELECT * FROM abonat");
        while($data=mysql_fetch_row($result)){
                if(($data[1]==$email)||($data[2]==$nume))
                    $z=0;
        }

        if($z==1){
           mysql_query("INSERT INTO abonat(email,nume) VALUES ('$email','$nume')");
           $mesaj="Your email has been registered";
        }
        else $mesaj="You are already registered";   
    }
    else $mesaj="You have not entered a valid email adress";
}
mysql_close($con);
header('Location:index.php');
?>
  • 写回答

2条回答 默认 最新

  • down_load1117 2013-04-29 10:29
    关注

    Try setting a cookie called e.g. $_COOKIE['status_message'] with 60 second timeout.

    set_cookie('status_message','This is our message',(time()+60));
    

    Then when the page is refreshed, check to see if the cookie has any data;

    if(isset($_COOKIE['status_message'])){
        echo $_COOKIE['status_message'];
        set_cookie('status_message','',(time()-3600));
    }
    

    This will echo out any populated message and destroy the cookie.

    本回答被题主选为最佳回答 , 对您是否有帮助呢?
    评论
查看更多回答(1条)

报告相同问题?

悬赏问题

  • ¥15 完成下列问题完成下列问题
  • ¥15 C#算法问题, 不知道怎么处理这个数据的转换
  • ¥15 YoloV5 第三方库的版本对照问题
  • ¥15 请完成下列相关问题!
  • ¥15 drone 推送镜像时候 purge: true 推送完毕后没有删除对应的镜像,手动拷贝到服务器执行结果正确在样才能让指令自动执行成功删除对应镜像,如何解决?
  • ¥15 求daily translation(DT)偏差订正方法的代码
  • ¥15 js调用html页面需要隐藏某个按钮
  • ¥15 ads仿真结果在圆图上是怎么读数的
  • ¥20 Cotex M3的调试和程序执行方式是什么样的?
  • ¥20 java项目连接sqlserver时报ssl相关错误