gpt4 book ai didi

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

转载 作者:行者123 更新时间:2023-11-29 05:00:15 24 4
gpt4 key购买 nike

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

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

最佳答案

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

您可以执行以下操作:

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

从这里开始,一切都应该是构建实际页面的通用功能。

关于php 将 Id 传递到下一页和从数据库,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/1890251/

24 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com