我写了一个php代码……</p>
// 如果点击检查会话是否设置
if(isset($_POST['reserve'])){ if(!empty($_SESSION['username'])){
$db->query(“INSERT INTO `reserve` (`r_b_id`,`r_m_id`,`r_date`) VALUES
(‘$book_id’,'$userId’,'$date’)”);
}else{
echo ‘ ‘; // I nee to display alert box here }}
如果会话未开始,则应显示警报消息。我该怎么做?我试过这样。但它没有用。
if(isset($_POST['reserve'])){
if(!empty($_SESSION['username'])){
$db->query(“INSERT INTO `reserve` (`r_b_id`,`r_m_id`,`r_date`) VALUES (‘$book_id’,'$userId’,'$date’)”);
}else{
echo ‘$(document).load(function(){
bootbox.alert(“You must login first”);
这是引导箱网站的链接... http://bootboxjs.com/#usage
这是我的完整代码
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
<html xmlns="http://www.w3.org/1999/xhtml">
<head>
<meta http-equiv="Content-Type" content="text/html; charset=utf-8" />
<title>Book Detail</title>
<link rel="stylesheet" href="../common/bootstrap/css/bootstrap.min.css" />
</head>
<body>
<?php
// Run the query to get each books detail.
$db->query("SELECT * FROM `book` WHERE `b_id` = '$book_id'");
foreach($db->resultsArray as $row){
echo "Id : ". $row['b_id'] . "<br />";
echo "Category : ". $row['b_cat_id'] . "<br />";
echo "Title : ". $row['b_title'] . "<br />";
echo "Author : ". $row['b_author'] . "<br />";
echo "Summery : ". $row['b_summary'] . "<br />";
}
// To get member id of loged in user's
$db->query("SELECT `userId` FROM `user` WHERE `username` = '$username'");
$userId = $db->resultsArray['0']['userId'];
// Get system date
$date = date("Y-m-d");
// Check reserve book button
// If click check the session is set or not
if(isset($_POST['reserve'])){
if(!empty($_SESSION['username'])){
$db->query("INSERT INTO `reserve` (`r_b_id`,`r_m_id`,`r_date`) VALUES ('$book_id','$userId','$date')");
}else{
echo '<script type="text/javascript">$(document).load(function(){ bootbox.alert("You must login first");})</script>';
}
}
?>
<form method="post" action="">
<input type="submit" name="reserve" class="btn" id="reserve" value="Reserve Book" />
</form>
<!-- JS dependencies -->
<script src="https://ajax.googleapis.com/ajax/libs/jquery/1.7.1/jquery.min.js"></script>
<script src="../common/bootstrap/js/bootstrap.min.js"></script>
<!-- bootbox code -->
<script type="text/javascript" src="https://raw.github.com/makeusabrew/bootbox/v2.4.2/bootbox.min.js"></script>
</body>
</html>