简体   繁体   English

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

[英]php passing Id to next page and from database

I am inserting some info into a database table with php and mysql. 我正在使用php和mysql将一些信息插入到数据库表中。 I am trying to diplay the same information inserted into the table in the next page. 我试图在下一页中显示插入表中的相同信息。

I know that if I send the ID it won't work becuase the row hasn't been created yet, it will display an empty page. 我知道如果我发送ID它将无法工作,因为尚未创建行,它将显示一个空页。 Is there a way around this? 有没有解决的办法? I need the information to come from the table. 我需要从表中获取信息。

Edit: If the row hasn't been created yet, it can't be returned by the DB. 编辑:如果尚未创建行,则DB无法返回该行。 Therefore, you are trying to access a given page in 2 different ways. 因此,您尝试以两种不同的方式访问给定页面。

You can do something like the following: 您可以执行以下操作:

$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.
}

From here on, everything should be common functionality for building the actual page. 从这里开始,一切都应该是构建实际页面的常用功能。

I'm confused by your question, as it makes it sounds like you are creating the record, then going to the next page, so why wouldn't be there? 我对你的问题感到困惑,因为它让你觉得你正在创建记录,然后转到下一页,那为什么不在那里呢?

otherwise, you could just throw it into $_SESSION. 否则,你可以把它扔进$ _SESSION。

I think mysql_insert_id will get you where you need to go. 我认为mysql_insert_id会让你到达你需要去的地方。 Insert the record, then call that and redirect the user to that id/ page. 插入记录,然后调用该记录并将用户重定向到该ID /页面。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM