hello,

i am creating a api, but i have run into a problem, its not returning anything when i call the action "profile" but everything else if working perfectly, please can you help me diagnose and ammend this problem thanks...

http://api.bititude.com/blueniverse/wardrobe.php?action=profile&friend=patch

<?php

////////////////////////////////////////////////////////////
// Title: Blueniverse Developers API                      //
// Developers: Nathaniel Blackburn, Rexzooly Kai Black    //
// Version: 1.0.0.0                                       //
// Revised: 15/06/2011 @ 20:00:00                         //
////////////////////////////////////////////////////////////

$action = strtolower($_GET['action']);
$friend = strtolower($_GET['friend']);

$hash = strtolower($_GET['hash']);
$token = md5($friend);

if ($action == ''){
	echo 'Invalid API Action: The following actions can be used: <b>avatar</b>, <b>profile</b>';
	
} elseif ($action == 'avatar'){

	if ($hash == '' && $friend == '') {
			echo 'Bad API Call: Please specify <b>friend</b> OR <b>hash</b> parameters';
	} else {
		if ($hash != '' && $friend != '') {
			echo 'Bad API Call: Please specify <b>friend</b> OR <b>hash</b> parameters';
		}
		if ($friend != '' && $hash == '') {
		
			$filepath = "wardrobe/$token";
			$errorpath = "wardrobe/cb5e100e5a9a3e7f6d1fd97512215282";

			if (is_readable($filepath)) {
				header("Content-Type: image/png");
				readfile($filepath);
			} else {
				header("Content-Type: image/png");
				readfile($errorpath);
			}
		
		}
		if ($hash != '' && $friend == ''){
		
			$filepath = "wardrobe/$hash";
			$errorpath = "wardrobe/cb5e100e5a9a3e7f6d1fd97512215282";

			if (is_readable($filepath)) {
				header("Content-Type: image/png");
				readfile($filepath);
			} else {
				header("Content-Type: image/png");
				readfile($errorpath);
			}	
		
		}
	}
	
}

if ($action == 'profile') {

	if ($hash == '' && $friend == '') {
		echo 'Bad API Call: Please specify <b>friend</b> OR <b>hash</b> parameters';

	} else {
		
		if ($hash != '' && $friend != '') {
			
			$hostname = ""; 
			$username = ""; 
			$password = ""; 
			$database = ""; 

			$connect = mysql_connect($hostname, $username, $password);
			
			if ($connect){

			if (mysql_select_db($database, $connect)){

					if ($friend != '' && $hash == '') {
						$query = "SELECT * FROM `wardrobe` WHERE `friend_name` = '$friend'"; 
					}
					if ($hash != '' && $friend == '') {
						$query = "SELECT * FROM `wardrobe` WHERE `friend_name` = '$token'"; 
					}
					
					$result = mysql_query($query, $connect); 

					if (!$result){
					
						$xml_output = "<?xml version=\"1.0\" encoding=\"utf-8\" standalone=\"yes\"?>\n"; 
						$xml_output .= "<wardrobe>\n"; 

						for($x = 0 ; $x < mysql_num_rows($result) ; $x++){ 
							$row = mysql_fetch_assoc($result); 
							$xml_output .= "\t<friend>\n"; 
							$xml_output .= "\t\t<friend_tag>" . $row['friend_tag'] . "</friend_tag>\n"; 
							$xml_output .= "\t\t<friend_name>" . $row['friend_name'] . "</friend_name>\n";
							$xml_output .= "\t\t<friend_description>" . $row['friend_description'] . "</friend_description>\n";
							$xml_output .= "\t</friend>\n"; 
						} 

						$xml_output .= "</wardrobe>"; 

						header("Content-type: text/xml");

						echo $xml_output; 

					} else {
						echo 'Bad API Call: Unable to find your friend.';
					}

				} else {
					echo 'Bad API Call: Unable to find database, please try again later.';
				}

			} else {
				echo 'Bad API Call: Unable to connect to the database, please try again later.';
			}
			
		}
	}

} else {
	echo 'Invalid API Action: The following actions can be used: <b>avatar</b>, <b>profile</b>';
}

?>

Kind Regards,
Nathaniel Blackburn

Not sure if this really helps, but just taking a jab at the logic...

If line 66 turns out to be true, then line 79 below it can NEVER be true, neither can line 82.

Not sure exactly HOW your API works, but you might try looking into your logic trails. :)

My 2¢. Hope this helps.

Not sure if this really helps, but just taking a jab at the logic...

If line 66 turns out to be true, then line 79 below it can NEVER be true, neither can line 82.

Not sure exactly HOW your API works, but you might try looking into your logic trails. :)

My 2¢. Hope this helps.

Thanks, i managed to sort everything out on my own and its working like a dream now but i do however appreciate the time you have spent assisting me, thanks again :)

Be a part of the DaniWeb community

We're a friendly, industry-focused community of developers, IT pros, digital marketers, and technology enthusiasts meeting, networking, learning, and sharing knowledge.