dongrenshi0889 2011-06-29 23:00
浏览 22
已采纳

中断$ _POST到预览输入

I have set up a database and have form data being submitted to it via $_POST in PHP, and I also have my page set up and working which pulls in the fields from the database and displays them. Not rocket science I know.

However what I want to do now is place a page inbetween the submission of the form and the insert in the database, to give the user a chance to check their entry.

I have created this page and used the $_POST data to display the data from the form (as it has not been entered into the database yet), however i'm wondering how, if the user approves the submission, I then INSERT it into the database. (I've tried running the INSERT query from the $_POST data on pressing a submit button, however because (I assume) ivew interrupted the flow between the original form submission and the INSERT query, all I get is a list of errors for unrecognised variables.

So what I have is this process:

form.php /user enters info using $_POST

preview.php /user is previewed info using $_POST and Session code starts (below)

submit.php /MySql query runs but returns all errors for undefined indexes

This is my session start code:

session_start();
if (isset($_POST['preview'])) { 
    $_SESSION['company_name'] = $_POST['company_name'];
    etc etc - remaining form field names
} 
  • 写回答

3条回答 默认 最新

  • dongzi3805 2011-06-29 23:05
    关注

    POST data is not automatically passed on to other pages. Save the submitted data in the session and read it from there after the confirmation page, or insert all that data back into the page using <input type="hidden"> elements, so they can be resubmitted as POST.

    A very simple illustration of the process using sessions:

    form.php

    <form action="confirm.php" ...>
        ...
    </form>
    

    confirm.php

    <?php
    session_start();
    $_SESSION['data'] = $_POST;
    ?>
    
    Please confirm:
    
    Name: <?php echo htmlspecialchars($_POST['name']); ?>
    ...
    
    <a href="save.php">Confirm</a>
    

    save.php

    <?php
    session_start();
    $data = $_SESSION['data'];
    
    // save $data to database
    
    本回答被题主选为最佳回答 , 对您是否有帮助呢?
    评论
查看更多回答(2条)

报告相同问题?

悬赏问题

  • ¥15 用三极管设计—个共射极放大电路
  • ¥15 请完成下列相关问题!
  • ¥15 drone 推送镜像时候 purge: true 推送完毕后没有删除对应的镜像,手动拷贝到服务器执行结果正确在样才能让指令自动执行成功删除对应镜像,如何解决?
  • ¥15 求daily translation(DT)偏差订正方法的代码
  • ¥15 js调用html页面需要隐藏某个按钮
  • ¥15 ads仿真结果在圆图上是怎么读数的
  • ¥20 Cotex M3的调试和程序执行方式是什么样的?
  • ¥20 java项目连接sqlserver时报ssl相关错误
  • ¥15 一道python难题3
  • ¥15 牛顿斯科特系数表表示