php将Id传递到下一页和数据库

时间:2009-12-11 19:12:15

标签: php mysql

我使用php和mysql将一些信息插入到数据库表中。我试图在下一页中显示插入表中的相同信息。

我知道如果我发送ID它将无法正常工作,因为尚未创建该行,它将显示一个空页面。有没有解决的办法?我需要从表格中获取信息。

3 个答案:

答案 0 :(得分:2)

编辑:如果尚未创建该行,则DB无法返回该行。因此,您尝试以两种不同的方式访问给定页面。

您可以执行以下操作:

$object = null;
if (isset($_REQUEST['id'])) {
    //call the DB to access the record data and put it 
    //into the $object that's representing that table.
}
else if (isset($_SESSION['data to display'])) {
    //retrieve that data and set the values on $object
    //then...
    unset($_SESSION['data to display']);
}
else {
    // bad input data. either call die() with an error message, 
    //or redirect to an error page, or do whatever else you might 
    //want to do.
}

从现在开始,一切都应该是构建实际页面的常用功能。

答案 1 :(得分:1)

我对你的问题感到困惑,因为这听起来好像你正在创建记录,然后转到下一页,那么为什么不在那里呢?

否则,你可以把它扔进$ _SESSION。

答案 2 :(得分:1)

我认为mysql_insert_id会让你到达目的地。插入记录,然后调用该记录并将用户重定向到该id / page。

相关问题