problem with log in code
Posted: Tue Nov 06, 2012 9:59 am
I am making a website where users can create an account and sign in. So in the website is a userbar with says: 'sign in or create account'
Everything is working fine accept after a user logs in, the userbar should change to 'Hello (then username)' but it doesn't.
The userbar stays as 'sign in or create account' even though the user is signed in. If i click sign in again a message appears saying already signed in.
here is my code for the userbar:
and then in all my other pages i include this code to display the userbar:
i know the problem is with the if statement - this line doesn't work if(isset($_SESSION['signed_in']) == true)
it keeps jumping into the else
Everything is working fine accept after a user logs in, the userbar should change to 'Hello (then username)' but it doesn't.
The userbar stays as 'sign in or create account' even though the user is signed in. If i click sign in again a message appears saying already signed in.
here is my code for the userbar:
Code: Select all
<?php
$host = "localhost";
$username = "root";
$password = "";
$database = "k00127082";
//error with connection
if(!mysql_connect($host, $username, $password))
{
exit('Error: could not establish database connection');
}
if(!mysql_select_db($database))
{
exit('Error: could not select the database');
}
if(isset($_SESSION['signed_in']) == true)
{
echo 'Hello <b>' . ($_SESSION['userName']) . '</b>. <a href="signout.php">Sign out</a>';
}
else
{
echo '<a href="signin.php">Sign in</a> or <a href="signup.php">create account</a>';
}
?>
and then in all my other pages i include this code to display the userbar:
Code: Select all
<div id="userbar">
<?php
include 'userbar.php';
?>
</div>
it keeps jumping into the else