我目前正在开发在线预订系统。在下面的脚本中,我已经构建了一个脚本,它将所有细节和成功重定向到另一个页面。 我的问题是如何在标题页上弹出一条成功的消息。
这是脚本
$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();
}
答案 0 :(得分:2)
最简单的解决方案是使用会话。
if($statement->execute()){
$_SESSION['message'] = "Your message here";
header('Location: activebookings.php');
}
(如果您此时尚未使用会话,则可能需要先致电session_start()
)
然后在您的activebookings.php页面上从会话中读取它(同样,您可能需要先调用session_start()
):
if (isset($_SESSION['message'])) {
echo '<script type="text/javascript">alert("' . $_SESSION['message'] . '");</script>';
unset($_SESSION['message']);
}
您需要取消会话中的消息,以确保访问者在刷新页面时不会再次显示该消息。
答案 1 :(得分:1)
你可以在标题之前使用$ _SESSION变量,将名为status的会话变量设置为1或类似的东西,然后在activebookings上检查会话变量,如果它存在,你可以回显弹出模态所需的javascript。
在预订页面
var images = ["https://baconmockup.com/300/200/","https://baconmockup.com/300/200/","https://baconmockup.com/300/200/","https://baconmockup.com/300/200/","https://baconmockup.com/300/200/","https://baconmockup.com/300/200/","https://baconmockup.com/300/200/","https://baconmockup.com/300/200/","https://baconmockup.com/300/200/","https://baconmockup.com/300/200/","https://baconmockup.com/300/200/","https://baconmockup.com/300/200/","https://baconmockup.com/300/200/","https://baconmockup.com/300/200/","https://baconmockup.com/300/200/"];
function render(){
var imageGroups = groupBy(4, images);
return (<div>
{imageGroups.map(renderRow)}
</div>);
}
function renderRow(group, index){
return (<div className="row" key={index}>
{group.map(renderColumn)}
</div>);
}
function renderColumn(image, index){
return (<div className="col-xs-3" key={index}>
<img src={image} />
</div>);
}
function groupBy(amountOfItemsPerGroup, items){
var groups = [],
group,
total = items.length;
for (var i=0; i < total; i += amountOfItemsPerGroup) {
group = items.slice(i, i+amountOfItemsPerGroup);
groups.push(group);
}
return groups;
}
ReactDOM.render(
render(),
document.getElementById('root')
);
on activebooking(你想弹出的地方)
$_SESSION['status'] = 1;
答案 2 :(得分:0)
使用echo显示如下的js警告:
Observable<User>
如果您想将会话数据放入警报,请确保您的消息没有任何&#34;或者&#39;不干涉语法
像这样:
echo "<script>alert('Success');</script>";
希望我有所帮助!