[英]How to retrieve the Id of the Last inserted data in to a "New Page" in php?
I created a sign up page in PHP.我在 PHP 中创建了一个注册页面。 When the submit button is clicked, it should show the registration No. on a NEW PAGE, (like "Your registration is successful and ur registration No. is____").当点击提交按钮时,它应该在新页面上显示注册号,(如“您的注册成功,您的注册号是____”)。 I Know how to show the last inserted ID on the same page.我知道如何在同一页面上显示最后插入的 ID。 but how to display the same on a NEW PAGE using mysql_insert_id()?但是如何使用 mysql_insert_id() 在新页面上显示相同的内容?
Below is the SIGN UP PAGE..下面是注册页面..
<?php include 'connect1.php'; if (isset($_POST['submit'])) { $name = $_POST['name']; $qual = $_POST['qual']; $dob = $_POST['dob']; $address = $_POST['address']; $number = $_POST['number']; $email = $_POST['email']; { $sql="INSERT INTO registeredparticipants (Name, DateOfBirth, Address, PhoneNumber, EmailID, Qualification)" . "VALUES ( '$name','$dob', '$address', '$number', '$email', '$qual' )"; $res=mysqli_query($con, $sql); if($res) { header('location: welcome.php'); } else { die ("Query Failed !!" . mysqli_error($con)); } }
When submit button is clicked, "welcome" page will be loaded.单击提交按钮时,将加载“欢迎”页面。 and i would like to display the ID of the last inserted data in "welcome" page.我想在“欢迎”页面中显示最后插入数据的 ID。 ID of the above table is "Reg_no."上表的ID为“Reg_no”。 How to dispaly it on "welcome" page.如何在“欢迎”页面上显示它。 ?? ??
Thanks in advance.. :)提前致谢.. :)
You can do it by either get |你可以通过 get | post |发布 | COOKIE |饼干 | SESSION会议
header("location:new_page.php?id=".$last_inserted_id) and get from $_GET['id'] on new_page.php header("location:new_page.php?id=".$last_inserted_id) 并从 new_page.php 上的 $_GET['id'] 获取
In html form hidden format " and get it from $_POST['id'] on new_page.php以 html 形式隐藏格式 " 并从 new_page.php 上的 $_POST['id'] 中获取
You can put into the url you are using to redirect like header("location:new_page.php?id=".$last_insert_id)
and get from $_GET['id']
on new_page.php您可以放入用于重定向的 url,如header("location:new_page.php?id=".$last_insert_id)
并从header("location:new_page.php?id=".$last_insert_id)
$_GET['id']
Hope it helps希望能帮助到你
There are two ways for this answer using $_GET and $_SESSION, get will show id in url if you dont want that use session for that.这个答案有两种使用 $_GET 和 $_SESSION 的方法,如果您不希望使用会话,get 将在 url 中显示 id。
$sql = "INSERT INTO ......";
if (mysqli_query($conn, $sql)) {
$last_id = mysqli_insert_id($conn);
$_SESSION['registration_no']=$last_id;
header("Location:newpage.php");
} else {
echo "Error: " . $sql . "<br>" . mysqli_error($conn);
}
in newpage.php在 newpage.php 中
<?php session_start(); ?>
Your registration is successful and ur registration No. is <?php echo $_SESSION['registration_no']; ?>
i hope it will help我希望它会有所帮助
you can use session
to store such value and retrieve it on any page you want like-你可以使用session
来存储这样的值并在你想要的任何页面上检索它 -
session_start();
//your code....
$_SESSION['reg_no'] = $last_insert_id;
than on any page you can retrieve it -比在任何页面上都可以检索它-
session_start();
$reg_no = $_SESSION['reg_no'];
echo "Your registration is successful and ur registration No. is ".$reg_no;
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.