if the user has not logged in, but click to the order page, then it should be redirect to the login page. yet, it is not functioned as expected. it just hold in the login page, and cannot login or proceed to order page. wt is the problem??
order form::
// 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);
}
}
?>
login check:
<?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);
?>