如果用户没有登录,但是点击到了订单页面,那么它应该被重定向到登录页面。然而,它并没有按预期运行。它只停留在登录页面,无法登录或进入订购页面。wt是问题吗??
订单::
// Connects to your Database
$connect = mysql_connect("127.0.0.1","root","") or die("not connecting");
mysql_select_db("shop") or die("no db :'(");
// is the one accessing this page logged in or not?
if ( !isset($_SESSION['logged-in']) || $_SESSION['logged-in'] !== true)
{
// not logged in, move to login page
header('Location: member_login.php');
exit();
}
else
{
//count the number of food
$food_num = mysql_query("select count(*) as sum from food");
$ttl_num= mysql_fetch_array($food_num);
//select the price of each food item
for($i=1; $i<=$ttl_num['sum']; $i++){
$price_query = mysql_query("SELECT price FROM food where foodid = '$i'");
$price_array= mysql_fetch_array($price_query);
$price_food[$i]=$price_array['price'];
//select the name of each food item
$name_query = mysql_query("SELECT name FROM food where foodid = '$i'");
$name_array= mysql_fetch_array($name_query);
$name_food[$i]=$name_array['name'];
mysql_close($connect);
}
}
?>
登录检查:
<?php
$connect = mysql_connect("127.0.0.1","root","") or die("not connecting");
mysql_select_db("shop") or die("no db :'(");
$form = $_POST['submit'];
$email = $_POST['loginID_member'];
$password = $_POST['password_member'];
if( isset($form) )
{
if( isset($email) && isset($password) && $email !== '' && $password !== '' )
{
$sql = mysql_query("SELECT * FROM member WHERE memberemail='$email' and memberpw='$password';");
if( mysql_num_rows($sql) != 0 ) { //success
$_SESSION['logged-in'] = true;
header('Location: order_form.php');
exit;
}
else
{
echo "<script>alert('Incorrect email or password!');window.location.href='member_login.php';</script>";
}
}
else
{
die('<script type="text/javascript">alert("Please enter a username and password!");location.replace("member_login.php")</script>');
}
}
mysql_close($connect);
?>