I made an account "hello" in bitcoin daemon and wanted to run this. Whenever i put in hello when prompted, getac1 would return empty array; whereas, getac2 and getac3 returns addresses associated with account hello. What am I missing? Assume I put in proper username, password, ip address, and port.

$bitcoin = new Bitcoin("username", "password", "ip address", "8332");
//prompt function
function prompt($prompt_msg){
   echo("<script type='text/javascript'> var answer = prompt('".$prompt_msg."'); </script>");
   $answer = "<script type='text/javascript'> document.write(answer); </script>";

$prompt_msg = "Please enter account name";
$name = prompt($prompt_msg);

$getac1 = $bitcoin->getaddressesbyaccount($name);
$getac2 = $bitcoin->getaddressesbyaccount("hello");
$getac3 = $bitcoin->getaddressesbyaccount(hello);

echo "</pre>";
  • Welcome to Bitcoin.SE! I will have a look at your question and see if I can come up with an answer.
    – Willtech
    Feb 9 '18 at 11:17

This looks like a subtle issue with the code you are using and I do not think you are taking a sensible approach to getting the name back from the input. The javascript will not execute inside of your PHP, it only runs when sent to the browser.

When it executes your function prompt is called but the return is everything inside the quotes on line 7, which is not what you typed into the input but is exactly what is inside the quotes:

$answer = "<script type='text/javascript'> document.write(answer); </script>";

I should ask, in what mode are you executing or calling your PHP - PHP can be executed standalone or it can execute with a browser page request.

I would solve this in a very rudimentary fashion by creating a HTML form which only displays if some $POST option is not set with the input, setting up the form to post back to the same URL and checking first for the $POST data as said. Then, if the $POST data is set, go ahead and create the output page - all in the one PHP file.

  • I'm calling PHP with a browser page request. Could you perhaps point me to a direction I can research so I can fix this? I'm pretty new at php so I'm not really sure what I'm doing
    – kjrew2001
    Feb 12 '18 at 5:29

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.