Reputation: 3
I'm doing a project at the moment and I'm trying to get a user name to display on pages when they login. I've tried to echo the user name in various places but it won't work for me. Could anyone tell me what code to enter and where please?
<?php
mysql_connect("localhost", "root", "") or die(mysql_error());
mysql_select_db("project") or die(mysql_error());
if(isset($_COOKIE['ID_my_site']))
{
$username = $_COOKIE['ID_my_site'];
$pass = $_COOKIE['Key_my_site'];
$check = mysql_query("SELECT * FROM users WHERE username = '$username'")or die(mysql_error());
while($info = mysql_fetch_array( $check ))
{
if ($pass != $info['password'])
{ header("Location: login.php");
}
else
{
echo "Admin Area<p>";
echo "Your Content<p>";
echo "<a href=logout.php>Logout</a>";
}
}
}
else
{
header("Location: login.php");
}
?>
Upvotes: 0
Views: 109
Reputation: 79
if $username variable having email id then Just select the username using your existing query. then save in session variable or cookie. then echo this session variable wherever you want.
or if $username variable having username then simply echo it. echo ($username = $_COOKIE['ID_my_site']);
Upvotes: 0
Reputation: 104
Here is a diagnostic idea, first see that you definately have a strig in the variable
echo ($username = $_COOKIE['ID_my_site']);
Once you definately have this you should be able to echo it further down in the html section
Upvotes: 1