如何获取最后插入的ID并再次发送

问题描述 投票:0回答:3

如何将lastInsertId再次发送到另一个php文档?

解释原因:在某人将表单(form.html)发送到数据库(send.php)后,他将获得该表单的ID。这个ID我通过PDO在send.php中显示给该人:

<p>Your ID:<?php echo $dbh->lastInsertId(); ?></p>

在这个确认页面,我想让这个人有可能从他的表格中打印数据作为pdf。所以我写道:

<form action="print.php" method="POST"> 
<input type="hidden" name="ID" value="<=htmlspecialchars($_POST['lastInsertId']);?>"/>
<input type="submit" name="Print" value="Print" >
</form>

但是我没有发送lastInsertId - >我想这里的问题是:

value="<?=htmlspecialchars($_POST['lastInsertId']);?>"

你能帮我解决这个问题吗?

printing send lastinsertid
3个回答
0
投票

你的代码应该是这样的:

<form action="print.php" method="POST"> 
<input type="hidden" name="ID" value="<?php echo $dbh->lastInsertId(); ?>"/>
<input type="submit" name="Print" value="Print" >
 </form>

0
投票

不确定这是不是最好的方式,但我曾经需要注册人的最后一个ID。将信息插入数据库后我执行了以下操作(我的表具有自动增量主键ID):

$lastId = mysqli_insert_id($con);

您可以将ID存储在任何您想要的位置。 (在URL或cookie中)

希望这可以帮助 (:


0
投票

非常感谢你!这有帮助。

是他们按下打印后的简单方法(现在使用ID获取数据库中的所有数据,以便在网站print.php显示它 - 该部分全部有效)并且现在直接要求保存为pdf?

© www.soinside.com 2019 - 2024. All rights reserved.