Bitcoin Forum
December 10, 2016, 10:22:44 PM *
News: To be able to use the next phase of the beta forum software, please ensure that your email address is correct/functional.
 
   Home   Help Search Donate Login Register  
Pages: [1]
  Print  
Author Topic: help with Bitcoin development in php (variable parameters)  (Read 4836 times)
altoid
Jr. Member
*
Offline Offline

Activity: 48


View Profile
April 25, 2011, 02:17:14 AM
 #1

Hi all, I have run into some trouble using the bitcoin api with php.  When I issue a command like:

$bitcoin->sendfrom($userid, $receiving_address, $amount);

I get an error like:

fopen(http://...@localhost:8332/): failed to open stream: HTTP request failed! HTTP/1.1 500 Internal Server Error

But when I hard code in the parameters:

$bitcoin->sendfrom("1", "1LDNLreKJ6GawBHPgB5yfVLBERi8g3SbQS", 10);

it works fine.

I did notice that I had to put quotes around the variables in my parameters for other functions to work.  For example:

$bitcoin->getnewaddress("$userid");

But every combination of quotes or no quotes produces the error in the sendfrom function.

Thanks in advance for any help you can give.  Let me know if you need more info too.
Advertised sites are not endorsed by the Bitcoin Forum. They may be unsafe, untrustworthy, or illegal in your jurisdiction. Advertise here.
1481408564
Hero Member
*
Offline Offline

Posts: 1481408564

View Profile Personal Message (Offline)

Ignore
1481408564
Reply with quote  #2

1481408564
Report to moderator
nodemaster
Full Member
***
Offline Offline

Activity: 176



View Profile WWW
April 25, 2011, 06:45:49 AM
 #2

I don't know the PHP API, but a 500 error from a webserver means: "Woah, something went wrong but I can't tell what". Given that the request works if you hardcode the parameters I'd guess it is more likely, that the variables you use contain values, that are not correct. Try to output them for debugging purpose before you use sendfrom(). From what I see (guessed) the data types should be:

$id                Integer  No quotes
$received_address  String   Quotes
$amount            Float    No Quotes


I hope this helps.
genjix
Legendary
*
expert
Offline Offline

Activity: 1232


View Profile
April 25, 2011, 08:09:19 AM
 #3


$id                Integer  No quotes
$received_address  String   Quotes
$amount            Float    No Quotes


Your problem is that $userid needs to be a string. You can cast it using (string)$userid.
altoid
Jr. Member
*
Offline Offline

Activity: 48


View Profile
April 25, 2011, 03:41:09 PM
 #4

Thank you sooooooooooooooo much!

The the problem was they were all strings.  I cast the $amount as a float and it worked!

$amount = (float)$amount;

Are there any weird variable type requirements I might run across in the other commands, or are they all strings floats and ints?
Gavin Andresen
Legendary
*
qt
Offline Offline

Activity: 1652


Chief Scientist


View Profile WWW
April 25, 2011, 05:50:30 PM
 #5

RE: other weird variable type requirments:
sendmany's second argument is a JSON Object, with string keys and number (float) values.  I think the equivalent in PHP is a PHP Array (indexed by string).

Several routines take boolean arguments.
All the rest are strings or numbers.


How often do you get the chance to work on a potentially world-changing project?
Pages: [1]
  Print  
 
Jump to:  

Sponsored by , a Bitcoin-accepting VPN.
Powered by MySQL Powered by PHP Powered by SMF 1.1.19 | SMF © 2006-2009, Simple Machines Valid XHTML 1.0! Valid CSS!