【发布时间】:2020-06-04 23:39:48
【问题描述】:
我正在尝试创建一个自动填充信息按钮,该按钮从 MySQL 检索最后插入的信息,并与 $_GET 结合使用最新更新自动填充页面。我可以很好地插入和更新数据库,但是在检索到信息后,我的变量仍然为空。
我已确认正在发布项目填充按钮。检查查询时我也没有收到任何错误。
下面是不工作部分的 sn-p。它打印我的标题,但变量保持为空。
为草率的代码道歉。
if(isset($_POST['project-fill'])) {
require "dbh.inc.php";
//select the last inserted row the one with the highest id
$proj1 = mysqli_query($conn, "SELECT * FROM updates WHERE id = MAX");
$proj2 = mysqli_query($conn, "SELECT * FROM updates WHERE id = MAX");
$proj3 = mysqli_query($conn, "SELECT * FROM updates WHERE id = MAX");
//select the column out of that row
$result1 = mysqli_fetch_row($proj1['Project1']);
$result2 = mysqli_fetch_row($proj2['Project2']);
$result3 = mysqli_fetch_row($proj3['Project3']);
//transfer to project variable
$project1 = $result1;
$project2 = $result2;
$project3 = $result3;
//print header to allow for the $_GET method on the project page
header (Location: ../update.php?update=sucessful&p1=".$project1."&p2=".$project2."&p3="$.project3);
}
【问题讨论】:
-
我没有看到你在呼应任何东西。另外,您不需要 3 个查询。你的header 也是错误的。
-
我使用 $_GET 方法在另一个页面表单上回显该变量以从标题中检索它。这就是为什么我让标题脚本在检索每个相应变量的信息时更新标题。
-
不要更改问题以匹配答案。那么没有人会理解我在答案中解决的问题。