im having a little problem with my users profile pages and an if statement on the profile page!
i have a link on profile pages to add the user as a friend which should disappear and change to 'you are friends' when the request is accepted.
the problem is, it echoes both the link and 'you are friends'!
here is my code:
(the problem area is highlighted in italics)
Code:
<?
/* Requested Username error checking */
$req_user = trim($_GET['user']);
if(!$req_user || strlen($req_user) == 0 ||
!eregi("^([0-9a-z])+$", $req_user) ||
!$database->usernameTaken($req_user)){
die("Username not registered");
}
/* Logged in user viewing own account */
if(strcmp($session->username,$req_user) == 0){
echo '<font size=\'6\' color=\'#0C009D\'><b>My Profile</b></font><br><br>';
}
/* Visitor not viewing own account */
else{
$req_user_info = $database->getUserInfo($req_user);
echo '<font size=\'6\' color=\'#0C009D\'><b>'.$req_user_info['username'].'\'s Profile</b></font><br>';
echo "<a href='".$req_user_info['fburl']."' title=\"View ".$req_user_info['username']."'s Facebook Profile\" target=\"_blank\"><img src=\"Facebook_icon.gif\" width=\"25\" height=\"25\" border=\"0\" /></a>  ";
echo "<a href=\"usermsg.php?username=".$req_user_info['username']."\" title=\"Send ".$req_user_info['username']." A Message\"><img src=\"comment.png\" width=\"25\" height=\"25\" border=\"0\" /></a>  ";
echo "<a href=\"mailto:".$req_user_info['email']."\" title=\"Send ".$req_user_info['username']." An Email\"><img src=\"email.png\" width=\"25\" height=\"25\" border=\"0\" /></a>  ";
$get = mysql_query( "SELECT * FROM `friends` WHERE `username` = '$session->username' "); //gets friends
while ($fris = mysql_fetch_array($get)){
if ($fris['friendname'] == $req_user_info['username']){ //checks if user is already a friend
echo ( "You are friends" );
}
else{
echo ( "<a href='friendrequest.php?user=$req_user_info[username]'>Add as Friend</a>");
}
}
}
/* Display requested user information */
$req_user_info = $database->getUserInfo($req_user);
/* Avatar (assumes you have a default for folks who don't upload an avatar, here it is called "no_avatar.gif")*/
if($req_user_info['avatar'] == 0){
echo '<img src="include/userimg/no_avatar.jpg" width="150" height="150"/>';
}
else{
echo '<img src="include/userimg/'.$req_user_info['avatar'].'" width="150" height="150"/>';
}
/* Username */
echo "<br><br><font color='#003399'><b>Username:</b></font><br> ".$req_user_info['username']."<br><br>";
/* Email */
echo "<font color='#003399'><b>Email:</b></font><br> ".$req_user_info['email']."<br><br>";
/* country */
echo "<font color='#003399'><b>Location:</b></font><br> ".$req_user_info['city'].", ".$req_user_info['country']."<br><br>";
/* Games */
echo "<font color='#003399'><b>My Games:</b></font><br> ".$req_user_info['games']."<br><br>";
/* About */
echo "<font color='#003399'><b>About Me:</b></font><br> <em>".$req_user_info['about']."<br><br></em>";
$timestamp = $req_user_info['timestamp'];
echo "<br><font color='#003399'><b>Last Active:</b></font><br> ".date('jS F Y \a\\t g.ia', $timestamp)." <br><br>";
/**
* Note: when you add your own fields to the users table
* to hold more information, like homepage, location, etc.
* they can be easily accessed by the user info array.
*
* $session->user_info['location']; (for logged in users)
*
* ..and for this page,
*
* $req_user_info['location']; (for any user)
*/
/* If logged in user viewing own account, give link to edit */
if(strcmp($session->username,$req_user) == 0){
echo "<br>[<a href=\"useredit.php\">Edit Profile</a>]<br>";
}
/* Link back to main */
echo "<br>Back To [<a href=\"index.php\">Main</a>]<br>";
?>
any suggestions?
your help is appreciated!
Bookmarks