p2p.wrox.com Forums

p2p.wrox.com Forums (http://p2p.wrox.com/index.php)
-   Beginning PHP (http://p2p.wrox.com/forumdisplay.php?f=95)
-   -   $_Session cant pass Value (http://p2p.wrox.com/showthread.php?t=40082)

kelz84 March 20th, 2006 11:34 AM

$_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>



kelz84 March 21st, 2006 09:25 AM

anyone can help or understand my problem? nvm anyway is there possibility i need to do some setting so that my session only will work? i tried this 2 simple example and it doesn't work for me as well.

test2.php :
<?php
    session_start();
    $_SESSION['user'] = 'kelz';
    //echo "<p>You Are now logged in, {$_SESSION['user']}!</p>";
    ob_end_clean();
    header( "Location: test3.php" );
    exit();
?>

test3.php :
<?php
    session_start();
    if (isset(!$_SESSION['user']))
    {
    header( "Location: loginerror.php" );
    exit();
    }
    $page_title = 'Logged In!';
    echo "<p>You Are now logged in, {$_SESSION['user']}!</p>";
?>


is there something wrong with my computer setting ? thx guys



All times are GMT -4. The time now is 07:13 AM.

Powered by vBulletin®
Copyright ©2000 - 2020, Jelsoft Enterprises Ltd.
© 2013 John Wiley & Sons, Inc.