I created a sign up page in 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. but how to display the same on a NEW PAGE using mysql_insert_id()?
我在PHP中创建了一个注册页面。单击提交按钮时,应在新页面上显示注册号,(例如“您的注册成功,注册号为_____”)。我知道如何在同一页面上显示最后插入的ID。但如何使用mysql_insert_id()在NEW PAGE上显示相同的内容?
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 of the above table is "Reg_no." How to dispaly it on "welcome" page. ??
单击提交按钮时,将加载“欢迎”页面。我想在“欢迎”页面中显示最后插入数据的ID。上表的ID是“Reg_no”。如何在“欢迎”页面上显示它。 ??
Thanks in advance.. :)
提前致谢.. :)
4 个解决方案
#1
0
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
<?php session_start(); ?>
Your registration is successful and ur registration No. is <?php echo $_SESSION['registration_no']; ?>
i hope it will help
我希望它会有所帮助
#2
1
You can do it by either get | post | COOKIE | SESSION
你可以通过get |来做到这一点发布| 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']获取
#3
0
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
您可以将您用于重定向的网址(“location:new_page.php?id =”。$ last_insert_id)放入您使用的网址中,并在new_page.php上获取$ _GET ['id']
Hope it helps
希望能帮助到你
#4
0
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;
#1
0
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
<?php session_start(); ?>
Your registration is successful and ur registration No. is <?php echo $_SESSION['registration_no']; ?>
i hope it will help
我希望它会有所帮助
#2
1
You can do it by either get | post | COOKIE | SESSION
你可以通过get |来做到这一点发布| 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']获取
#3
0
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
您可以将您用于重定向的网址(“location:new_page.php?id =”。$ last_insert_id)放入您使用的网址中,并在new_page.php上获取$ _GET ['id']
Hope it helps
希望能帮助到你
#4
0
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;