Author

Topic: 【SOLVED】PHP error help! (Read 1110 times)

legendary
Activity: 952
Merit: 1000
February 13, 2013, 05:30:42 AM
#8
Glad it was 【SLOVED】 Grin
member
Activity: 117
Merit: 10
Not only FUD :)
February 13, 2013, 05:23:27 AM
#7
Thank you.  The reason is that there are special characters in my password.
hero member
Activity: 812
Merit: 1000
February 13, 2013, 04:19:37 AM
#6
function check_balance()
{
   

   
      $jsonurl = "https://blockchain.info/merchant/".$GLOBALS['user']."/balance?password=".$GLOBALS['password'];
      $json = file_get_contents($jsonurl,0,null,null);

echo '
$json = ' . $json . '

';


      $json = json_decode($json);

print_r($json);
echo '
';

       $balance = $json->balance/ 100000000;
      
      
   
   return $balance;
}


let's see what's in that $json var first, so we know why the balance thing is throwing an error
member
Activity: 117
Merit: 10
Not only FUD :)
February 13, 2013, 01:16:14 AM
#5
function check_balance()
{
   

   
      $jsonurl = "https://blockchain.info/merchant/".$GLOBALS['user']."/balance?password=".$GLOBALS['password'];
      $json = file_get_contents($jsonurl,0,null,null);
      $json = json_decode($json);
      
       $balance = $json->balance/ 100000000;
      
      
   
   return $balance;
}
hero member
Activity: 812
Merit: 1000
February 12, 2013, 11:00:49 PM
#4
have you tried this by the way:

$balance = $json->balance / 100000000; // line 33

i'm not familiar with the script you're using... did you copy it from somewhere, or come up with that line yourself?


without further detail, it appears to me that the line you're using is looking inside the $json object for a property or method called $balance and then using the value of $balance to look for a further property or method of $json.

eg.

class jsonClass {
     $balance = 'mybalancevar';
     $mybalancevar = 33;
}

in this case, $json->{'balance'} would equal 33; while $json->balance would be a string: mybalancevar
BCB
vip
Activity: 1078
Merit: 1002
BCJ
February 12, 2013, 10:53:54 PM
#3
did you include the library you are referencing or is the path correct?
hero member
Activity: 812
Merit: 1000
February 12, 2013, 10:36:46 PM
#2
maomao, before line 33, can you

var_dump($json);

...if possible, pasting the whole script here might help.
member
Activity: 117
Merit: 10
Not only FUD :)
February 12, 2013, 10:25:40 PM
#1
get this warning in my error logs and wanted to know how to correct this issues in my code.

Warning: PHP Notice: Undefined property: stdClass::$balance in script.php on line 33





$balance = $json->{'balance'} / 100000000; // line 33
Jump to: