【发布时间】:2026-01-20 07:45:02
【问题描述】:
我正在尝试使用我所做的最后一个插入的一个 id 创建一个变量,并且我正在尝试将其粘贴到另一个页面。
在第一页这是代码:
$insert= "INSERT INTO resources (name,description,place,time) VALUES ('$name','$description','$place',CURDATE())";
mysql_query($insert);
$last_id= mysql_insert_id();
header("Location:new_page.php?last_id=$last_id");
在第二页这是我的代码:
<?php
echo "This is id of resource : $last_id";
?>
我做不到,有什么解决办法吗?
谢谢!
问候
【问题讨论】:
-
$_SESSION 变量将帮助您摆脱困境。 php.net/manual/en/reserved.variables.session.php
-
要从 URL new_page.php?last_id=$last_id 访问 last_id,您必须使用变量 $_GET['last_id']