Reputation: 2046
I'm currently working on the online booking system.In the script below, I have build a script which takes all the details and on success redirect it to another page. My question is how do i pop up a successful message on header page.
Here is the script
$statement = $db->prepare("INSERT INTO bookings (customerid, pname,cnumber, paddress, daddress, via, pdate, hours, mins, luggage, vtype, pnum, info) VALUES (?,?,?,?,?,?,?,?,?,?,?,?,?)");
$statement->bind_param('issssssiiisis', $user_id, $pname, $number, $pickupaddress, $dropaddress, $via, $date, $hours, $minutes, $luggages, $vtype, $passengers, $additional);
if($statement->execute()){
header('Location: activebookings.php');
}
}else{
die('Error : ('. $mysqli->errno .') '. $mysqli->error);
}
$statement->close();
}
Upvotes: 0
Views: 2623
Reputation: 335
Use the echo to display a js alert like this:
echo "<script>alert('Success');</script>";
If you want to put session data into the alert do this just be sure that your message doesn't have any " or ' to not interfere in the syntax
Like this:
echo "</script>alert("'.$_SESSION['your data'].'");</script>";
Hope i have helped!
Upvotes: 0
Reputation: 891
you can use a $_SESSION variable before the header, set a session variable called status to 1 or something like that and then on activebookings check for the session variable and if it exists you can echo the javascript needed to popup a modal.
on booking page
$_SESSION['status'] = 1;
on activebooking (where you want popup)
$status = $_SESSION['status']
if($status)
echo '<script>popup();</script>'
Upvotes: 1
Reputation: 11328
The easiest solution is to use sessions for that.
if($statement->execute()){
$_SESSION['message'] = "Your message here";
header('Location: activebookings.php');
}
(you may need to call session_start()
first, if you're not using sessions yet at this point)
Then on your activebookings.php page read it from the session (again, you may need to call session_start()
first):
if (isset($_SESSION['message'])) {
echo '<script type="text/javascript">alert("' . $_SESSION['message'] . '");</script>';
unset($_SESSION['message']);
}
You'll want to unset the message from the session, to make sure your visitors don't get the popup again if they refresh the page.
Upvotes: 2