[英]Php pop up successfull message after redirect to another page
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();
}
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) (如果您此时尚未使用会话,则可能需要先调用
session_start()
)
Then on your activebookings.php page read it from the session (again, you may need to call session_start()
first): 然后在您的activebookings.php页面上从会话中读取它(同样,您可能需要先调用
session_start()
):
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. 您需要取消会话中的消息设置,以确保访问者刷新页面后不会再次看到弹出窗口。
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. 您可以在标头之前使用$ _SESSION变量,将一个名为status的会话变量设置为1或类似的名称,然后在activebookings上检查该会话变量,如果存在该变量,则可以回显弹出模式所需的JavaScript。
on booking page 在预订页面上
$_SESSION['status'] = 1;
on activebooking (where you want popup) 在活动预订上(您要弹出的位置)
$status = $_SESSION['status']
if($status)
echo '<script>popup();</script>'
Use the echo to display a js alert like this: 使用echo来显示js警报,如下所示:
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! 希望我有所帮助!
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.