I am trying to get php to choose which link should appear depending on if this person is logged into my site using cookies.I tried to code this my self but it isn’t working.So How would I go about doing this the right way here is my code:
<?php
if(isset($_COOKIE['maxgee_me_user'])) {
$username = $_COOKIE['maxgee_me_user'];
$password = $_COOKIE['maxgee_me_password'];
$check = mysql_query("SELECT * FROM users WHERE username = '$username'")or die(mysql_error());
while($info = mysql_fetch_array( $check ))
{
//if the cookie has the wrong password, echo's login
if ($password != $_COOKIE['maxgee_me_password'])
{ ?> <a href="logout.php"><?php echo "Logout"; ?></a>  
<?php
else {
?> <a href="loginpage.php"><?php echo "User Login";} ?></a>
Quite a lot of errors on your code.
First of all, you need to use both user name and password when checking if a valid user exist. Assuming you have the pwd saved as well in you table.
And use mysql_num_rows($check)>0 to see if a valid user found.
Following is a complete code, but do note this is bad coding practise which you say you are working on it.