I have two form in my page. In first form user enters the details and submits it. Then the record will be saved in a database table. Then after from a button click I want to set a value from the data set which has been sent to the database to second form's hidden input. So for that when user submits the record from first form I am generating a unique id and sending it to the url. And also I am saving the unique id in my database table. Then after wrote the query to find the relevant data from relevant table using the unique id which is in url set the value to hidden input in my second form. But it's not working, I am providing my code here. Many thanks.
This is the action which will be performed from the first form's submission.
<?php
require_once('dbh.inc_2.php');
if (isset($_POST['confirm'])) {
$f_name=$_POST["first_name"];
$l_name=$_POST["last_name"];
$email=$_POST["email"];
$nationality=$_POST["nationality"];
$start_date=$_POST["date_start"];
$type=$_POST["package"];
$heads=$_POST["heads"];
$tot_amount=$_POST["total"];
$payment_amount=$_POST["advance"];
$unique_id = uniqid();
if (empty($f_name) || empty($l_name) || empty($email) || empty($nationality)|| empty($start_date) || empty($type) || empty($heads) || empty($tot_amount) || empty($payment_amount)) {
header("Location: ../book_trip.php?error=emptyfields&please_fill_all_the_fields");
exit();
}
else {
$sql ="INSERT INTO bookings(f_name, l_name, email, nationality, s_date, type, heads, tot_amount, payment, ui) VALUES('$f_name','$l_name','$email', '$nationality', '$start_date', '$type', '$heads', '$tot_amount', '$payment_amount', '$unique_id')";
if (mysqli_query($conn, $sql))
{
$m= "Booking placed";
}
else
{
$m= "Error: " . $sql . "<br>" . mysqli_error($conn);
}
require_once('PHPMailer/PHPMailerAutoload.php');
$mail = new PHPMailer();
$mail -> isSMTP();
$mail -> SMTPAuth = true;
$mail -> SMTPSecure = 'ssl';
$mail -> Host = 'smtp.gmail.com';
$mail -> Port = '465';
$mail -> isHTML();
$mail -> Username = '[email protected]';
$mail -> Password = 'wolfpack@123';
$mail -> SetFrom('[email protected]');
$mail -> Subject = 'Booking Confirmation - WolfPack';
$mail -> Body = 'Thank you for choosing us as your travel partner! We hope to provide you an amazing travel adventure. You will recieve an email shortly with up and down locations and time. ' ;
$mail -> AddAddress($email);
$mail -> Send();
}
}
header("location:../book_trip.php?msg=$m?ui=$unique_id");
This is to set the unique id to a variable which is on url and search for the data in database table using the unique id:
<?php
require_once 'includes_2/dbh.inc_2.php';
$d_name = "";
if (isset($_GET['ui'])) {
$dbook_id = $_GET['ui'];
$sql = mysqli_query($conn, "SELECT f_name FROM bookings WHERE ui=$dbook_id") or die (mysqli_error($conn));
while ($row = mysqli_fetch_array($sql, MYSQLI_ASSOC)) {
$d_name = $row["f_name"];
} }?>
mysqli_insert_id($con)