Wrox Programmer Forums

Need to download code?

View our list of code downloads.

Go Back   Wrox Programmer Forums > PHP/MySQL > Beginning PHP
Password Reminder
Register
| FAQ | Members List | Search | Today's Posts | Mark Forums Read
Beginning PHP Beginning-level PHP discussions. More advanced coders should post to the Pro PHP forum.
Welcome to the p2p.wrox.com Forums.

You are currently viewing the Beginning PHP section of the Wrox Programmer to Programmer discussions. This is a community of tens of thousands of software programmers and website developers including Wrox book authors and readers. As a guest, you can read any forum posting. By joining today you can post your own programming questions, respond to other developers’ questions, and eliminate the ads that are displayed to guests. Registration is fast, simple and absolutely free .
DRM-free e-books 300x50
Reply
 
Thread Tools Search this Thread Display Modes
  #1 (permalink)  
Old March 20th, 2006, 11:34 AM
Registered User
 
Join Date: Mar 2006
Location: , , .
Posts: 2
Thanks: 0
Thanked 0 Times in 0 Posts
Default $_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>


Reply With Quote
  #2 (permalink)  
Old March 21st, 2006, 09:25 AM
Registered User
 
Join Date: Mar 2006
Location: , , .
Posts: 2
Thanks: 0
Thanked 0 Times in 0 Posts
Default

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

Reply With Quote
Reply


Thread Tools Search this Thread
Search this Thread:

Advanced Search
Display Modes

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is Off
HTML code is Off
Trackbacks are Off
Pingbacks are On
Refbacks are Off


Similar Threads
Thread Thread Starter Forum Replies Last Post
$_SESSION error in login.php Mind Games Beginning PHP 1 June 2nd, 2008 03:43 PM
Difficulty with $_SESSION mall9@hotmail.com Beginning PHP 11 March 11th, 2006 05:41 PM
Is it possible to set $_Session Variables in java rinventive Java Basics 1 February 13th, 2006 05:41 AM
Storing binary data in $_SESSION variables richard.york Pro PHP 0 August 30th, 2003 05:23 PM
$_SESSION vs. $_GLOBALS Moharo Pro PHP 2 August 18th, 2003 02:27 PM



All times are GMT -4. The time now is 09:37 PM.


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