PDA

View Full Version : Why wont this code work :S



Moh
05-01-2008, 10:41 AM
Well im trying to get this code to check if the user is allready there friend, and if not displays a Ask to be friend button.
It needs to check:
If theres allready a "logged username and profile username" and a "profile username and a logged username" (So theres two places it could be).
The current code is below.

<?
include("config.php");
if($logged[username] && $logged[rank] == member OR admin OR mod){
$getfriend = mysql_query("SELECT * FROM friends");
$fr = mysql_fetch_array($getfriend);
if("$fr[to_user] = '$profile[username]' WHERE $fr[from_user] = '$logged[username]'"){
echo("<br><font size=\"1\">$profile[username] is already your friend!</font>");
} elseif ("$fr[to_user] = '$logged[username]' WHERE $fr[from_user] = '$profile[username]'"){
echo("<br><font size=\"1\">$profile[username] is already your friend!</font>");
} else {
echo("User isn't friend);
}
}
?>

I keep getting "User is already your friend" even when there not :l

Blob
05-01-2008, 11:44 AM
Your coding is crap.


<?php
include("config.php");

if( $logged["username"] )
{
if( $logged["rank"] == "member" || $logged["rank"] == "admin" || $logged["rank"] == "mod" )
{
$sql = mysql_query("SELECT * FROM friends");
$result = mysql_fetch_array($sql);
if( $result["to_user"] == $profile["username"] && $result["from_user"] == $logged["username"] )
{
echo '<br /><font size="1">' . $profile["username"] . ' is already your friend!</font>';
}
elseif( $result["to_user"] == $logged["username"] && $result["from_user"] == $profile["username"] )
{
echo '<br /><font size="1">' . $profile["username"] . ' is already your friend!</font>';
}
else
{
echo 'This user isn\'t your friend.';
}
}
}
?>

Moh
05-01-2008, 02:23 PM
Thanks, but theres 1 problem, once it gets the results from the first if, it dosn't do the other elseif's so is there a way do to it all on one if?

MrCraig
05-01-2008, 02:32 PM
Ew, dont use the techtuts usersystem :S

Mr Macro
05-01-2008, 02:35 PM
Do you even have a ask to be friend button in that code ?

Moh
05-01-2008, 02:37 PM
Do you even have a ask to be friend button in that code ?
Well im using a image button and it has the URL to the files so I removed it when I posted the code

Want to hide these adverts? Register an account for free!