Having issue with using 'getnewaddress' in multichain web demo

+1 vote
I am using the web demo and am trying to add code to give each user their own wallet address and have It stored in a MySQL data base. I am using "no_displayed_error_result($address, multichain('getnewaddress));" but nothing is saving to the $address variable. Any thoughts? thanks!
asked Aug 4, 2017 by bankdude

1 Answer

0 votes

It looks like you're missing a quote mark after getnewaddress, but if you post a larger snippet of your PHP code, we can give you a more informative answer.

answered Aug 5, 2017 by MultiChain
I have tried several different ways of attempting to get this to work, but with no luck. This was my most basic attempt. Thanks for the help!


 function NewUser()      {
                $getnewaddress = multichain('getnewaddress')
                $userName = $_POST['user'];
                $password = $_POST['pass'];


                
                $query = "INSERT INTO Users (Username, Password, WalletAddress) VALUES ('$userName','$password','$getnewaddress')";
                $data = mysql_query($query) or die(mysql_error());

                if($data)       {
                        echo "YOUR REGISTRATION IS COMPLETE";

                }

        }

 function SignUp(){
                if(!empty($_POST['user']))      {
                        $query = mysql_query("SELECT * FROM Users WHERE Username = '$_POST[user]'") or die(mysql_error());

                        if(mysql_num_rows($query) == 0)  {
                                
                                NewUser();
                        }

                        else    {
                                echo "That username is taken. Please try again!";
                        }
                }
        }



        if(isset($_POST['submit']))
        {
                SignUp();
        }
The basic code for accessing the MultiChain getnewaddress command looks right. So if it's not working the issue is likely that you haven't configured access to the MultiChain API correctly, or the node is not accepting incoming API requests from the IP address of your web server. See the README of the Web Demo for instructions on fixing all of that.

While we're here, you need to be *much* more careful about inserting user-provided data into your SQL queries. Looking up SQL injection attacks and SQL escaping for more information.
I don't think that is an issue because the rest of the "getnewadddress" commands are working. For example, the functionality of the "get new address" button on page-default is working fine; however, when trying to use that same functionality in a new script, we are getting no results.
OK. Did you include the same PHP files as those included by the web demo? Did you look in the error_log file for your web server to look for any errors?
...