$_Session cant pass Value
hi guys out there... really hope someone can help me out with my coding. i don't know why my session variable won't pass the value to the next page which means that i cant enter the 2nd page even i type in the correct username n password to login.here is the 2 page code. hopefully someone can help me thx alot.
the 1st page:
<?php
session_start();
include_once("connect_db.php");
$username = $_POST["txt_username"];
$password = sha1($_POST["txt_password"]);
$choice = $_POST["RadioGroup1"];
switch($choice) {
case 'parent':
//set up the query
$query = "SELECT * FROM parent WHERE username='$username' AND password='$password'";
//run the query and get the number of affected rows
$result = mysql_query($query) or die('error making query');
// if could not execute sql query
if ( !$result )
{
include_once ("loginerror.php");
exit();
}
else
{
// if there is any record fetched, means that username & password verified
$row = mysql_fetch_array( $result );
// successfully signing in
if ( $row )
{
$_SESSION['AUTH_USER'] = $username;
$setnow = date( "Y-m-d H:i:s" );
$updateQuery = "UPDATE parent SET last_sign_in = '$setnow' WHERE username = '$username' ";
// update query
mysql_query( $updateQuery );
header( 'Location: loginparent.php' );
}
else {
header('Location: incorrectlogin.php');
}
break;
}
case 'service_provider' :
$query = "SELECT * FROM service_provider WHERE username='$username' AND password='$password'";
//run the query and get the number of affected rows
$result = mysql_query($query) or die('error making query');
$affected_rows = mysql_num_rows($result);
//if there's exactly one result, the user is validated. Otherwise, he's invalid
if($affected_rows == 1) {
//add the user to our session variables
$_SESSION[ 'AUTH_USER' ] = $username;
header( 'Location: loginsp.php' );
}
else {
header('Location: incorrectlogin.php');
}
break;
mysql_free_result( $result );
}
?>
</p>
2nd page:
<?php
session_start();
if ( isset( $_SESSION['AUTH_USER'] ) )
{
?>
<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN" "http://www.w3.org/TR/html4/loose.dtd">
<html>
<head>
<title>Untitled Document</title>
<meta http-equiv="Content-Type" content="text/html; charset=iso-8859-1">
</head>
<body>
TEsting
<?php }
else
{
header( 'Location: loginerror.php' );
}
?>
</body>
</html>
|