Go Back   CodingForums.com > :: Server side development > MySQL

Before you post, read our: Rules & Posting Guidelines

Reply
 
Thread Tools Rate Thread
Enjoy an ad free experience by logging in. Not a member yet? Register.
Old 10-02-2011, 10:31 PM   PM User | #1
amcf1992
Regular Coder

 
Join Date: Jul 2011
Posts: 114
Thanks: 7
Thanked 0 Times in 0 Posts
amcf1992 is an unknown quantity at this point
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..
amcf1992 is offline   Reply With Quote
Old 10-03-2011, 12:31 AM   PM User | #2
Keleth
Senior Coder

 
Join Date: Jun 2008
Location: New Jersey
Posts: 2,354
Thanks: 45
Thanked 247 Times in 244 Posts
Keleth is on a distinguished road
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.
Keleth is offline   Reply With Quote
Reply

Bookmarks

Jump To Top of Thread


Thread Tools
Rate This Thread
Rate This Thread:

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 On
HTML code is Off

Forum Jump


All times are GMT +1. The time now is 10:46 PM.


Advertisement
Log in to turn off these ads.