不太明白,在 PHP 里,提交表单后,数据会自动清空,目前只有 ASP.NET 的 ViewState 有保留数据的功能.

解决方案 »

  1.   

    get是把信息保存在url里,没用。
    用cookie保存在客户端该怎么写?有没有例子?
    我刚开始学web编程。请多指教。
      

  2.   

    <?php
      
     if (isset($_POST['emp_id']))
     {   
      
        $expire = time()+60; //客户端cookie数据保存60秒
        setcookie("emp_id",$_POST['emp_id'],$expire);
        setcookie("emp_email",$_POST['emp_email'],$expire);
        Header("location:".$_SERVER['PHP_SELF']);
     }
     
    ?>
    <html>
    <body>
    <form method="post" action="<?php echo $_SERVER['PHP_SELF'];?>">
    <table border="0">
    <tr>
              <th align="right">Employee ID</th>
              <td><input name="emp_id" type="text" maxlength="8" size="24" value="<?php echo $_COOKIE['emp_id'];?>">
    </tr>
    <tr>
    <th align="right">Employee Email</th>
    <td><input name="emp_email" type="text" maxlength="40" size="24" value="<?php echo $_COOKIE['emp_email'];?>">
    </tr>
    <td>
    &nbsp;&nbsp;&nbsp;&nbsp;<input type="submit" name="submit" value="Add  New  Employee" />
    </td>
    </table>
    </form>
    <?php 
    if (isset($_COOKIE['emp_id']))
    {
    echo "上次提交数据:".$_COOKIE['emp_id']." ".$_COOKIE['emp_email'];
    echo "<br>";
    }
    else
    echo "您还没提交数据!<br>";
    ?>
    </body>
    <html>
      

  3.   

    虽然不大明白楼主的意思,不过我想用session吧
      

  4.   

    表单页面里面加上一个<iframe width=0 height=0 name=hidden></iframe>
    <form>标签上加上 target="hidden"
    处理页里最后一句后面加上
    echo("<script>top.location="表单页名称或者你想要转到的任何页面"</script>");
    这样用户看不到处理页 随便他怎么前进后退刷新都不会增加记录
      

  5.   

    在客户端加一段js脚本~~~服务器端的防止简直就是徒劳,人家存心要重复发贴,你是挡不住的~把这段代码放在页面最后:
    <script language="javascript" src="submitonlyonce.js"></script>
    代码submitonlyonce.js的内容:
    function doSubmitOnce(currentForm)
    {
    for(i=0;i<currentForm.length;i++)
    {
    var currentElement = currentForm.elements[i];
    if(currentElement.type.toLowerCase() == "submit")
    currentElement.disabled = true;
    }
    }
    if(document.all||document.getElementById) 
    {
    // Run through all forms on page
    for(i=0;i<document.forms.length;i++)
    {
    var currentForm = document.forms[i];
    var oldEventCode = (currentForm.onsubmit) ? currentForm.onsubmit : function () {};
    currentForm.onsubmit = function () {oldEventCode(); doSubmitOnce(currentForm)};
    }
    }