Hello and welcome to our community! Is this your first visit?
Register
Enjoy an ad free experience by logging in. Not a member yet? Register.
Results 1 to 2 of 2
  1. #1
    Regular Coder
    Join Date
    Jul 2011
    Posts
    140
    Thanks
    8
    Thanked 0 Times in 0 Posts

    Session data not passing

    dologin.php
    PHP Code:
    <?php 
    session_start
    ();
    ?>
    <html xmlns="http://www.w3.org/1999/xhtml">
    <head>
    <LINK href="includes/css/style.css" rel="stylesheet" type="text/css">
    <meta http-equiv="Content-Type" content="text/html; charset=utf-8" />
    <title>Login</title>
    </head>
    <body>
    <?php include('header.php');
    include(
    "dbsettings.php");  
    mysql_connect("$host""$username""$password")or die("mysql_error()");
    mysql_select_db("$db_name")or die("cannot select DB");  
       
    $username mysql_real_escape_string($_POST['username']);  
    $password md5(mysql_real_escape_string($_POST['password']));  


    $sql="SELECT * FROM `user` WHERE `username`='{$username}' AND `password`='{$password}'";  
    $result=mysql_query($sql);  
    if(
    mysql_num_rows($result) == 1)  
    {


        
    $_SESSION["id"] = $row["id"];
        
    $_SESSION["firstname"] = $row["firstname"];
        
    $_SESSION["lastname"] = $row["lastname"];
        
    $_SESSION["address"] = $row["address"];
        
             echo 
    '<META HTTP-EQUIV="Refresh" Content="0; URL=account.php">';


        }   

      else {
       
       
    echo 
    '<META HTTP-EQUIV="Refresh" Content="0; URL=failed.php">';



    }

    ?>
    <div id="loginsuccess">
    <div class="cntr">
    Please be Patient, we are logging you in. <br />
    <img src="includes/image/ajax-loader.gif" alt="ajax-loader.gif" width="43" height="11" />
    </div>
    </div>
    </body>
    </html>
    account.php


    PHP Code:
    <?php
    session_start
    ();
    ?>
    <html xmlns="http://www.w3.org/1999/xhtml">
    <head>
    <meta http-equiv="Content-Type" content="text/html; charset=utf-8" />
    <LINK href="includes/css/style.css" rel="stylesheet" type="text/css">
    <title>Account Dashboard</title>
    </head>
    <body>
    <?php

    include('header.php');
    include(
    "dbsettings.php");  
    mysql_connect("$host""$username""$password")or die("mysql_error()");
    mysql_select_db("$db_name")or die("cannot select DB");
    $result mysql_query("SELECT * FROM user
    WHERE username='{$username}'"
    );

    ?>
    <div class= "accountsummary">
    <?php
    if($_SESSION=='') {
    echo 
    '<META HTTP-EQUIV="Refresh" Content="0; URL=login.php">';
    }
    else if (
    $row mysql_fetch_array($result))
      {
    echo 
    $_SESSION['id'];
    echo 
    $_SESSION['firstname'];
    echo 
    $_SESSION['lastname'];
    echo 
    $_SESSION['address'];
    }
    else
    echo 
    "Database error";
    ?>
    </div>
    <p class="logout">
    <a href=logout.php>Logout</a>
    </p>

      <p style="position: absolute; top: 100px; left: 230px; background-color: white; margin: 15px; "> Welcome, <?php echo "$username"?> This is your account.<br />

     </p>
      <?php
    include('footer.php')
    ?>


    </body>  
    </html>
    </body>
    </html>
    Last edited by amcf1992; 10-02-2011 at 10:48 PM.

  • #2
    Senior Coder
    Join Date
    Jun 2008
    Location
    New Jersey
    Posts
    2,535
    Thanks
    45
    Thanked 259 Times in 256 Posts
    When asking for help, it tends to be useful to do more then just write down some code. So given the title, I'm guessing you're having trouble getting sessions to work. What have you tried to do to fix it? Have you tried putting session values outside of the if statements? If you print_r($_SESSION) anywhere, does it give you the data you expect?

    Also, its bad form, and technically wrong, to put a meta tag outside of the head tag. In addition, this has nothing to do with mySQL, and is a PHP question.


  •  

    Posting Permissions

    • You may not post new threads
    • You may not post replies
    • You may not post attachments
    • You may not edit your posts
    •