...

View Full Version : Session data not passing



amcf1992
10-02-2011, 10:31 PM
dologin.php

<?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
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>

Keleth
10-03-2011, 12:31 AM
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.



EZ Archive Ads Plugin for vBulletin Copyright 2006 Computer Help Forum