Pages:
Author

Topic: Question for the php-heads... (Read 1418 times)

hero member
Activity: 812
Merit: 1000
February 14, 2013, 08:56:04 AM
#29
PHP can sometimes do weird things with variable types... try this and get back to us:

Code:
$rucoin->sendfrom('', $addy, (float) $amount);

Hmmm, I will have to give that a try sometime, was actually coming back to report that I got it working with:

Code:
$rucoin->sendfrom('', $addy, (double)$amount);

just as good
sr. member
Activity: 294
Merit: 250
February 14, 2013, 08:40:30 AM
#28
PHP can sometimes do weird things with variable types... try this and get back to us:

Code:
$rucoin->sendfrom('', $addy, (float) $amount);

Hmmm, I will have to give that a try sometime, was actually coming back to report that I got it working with:

Code:
$rucoin->sendfrom('', $addy, (double)$amount);
hero member
Activity: 812
Merit: 1000
February 14, 2013, 05:35:04 AM
#27
sr. member
Activity: 294
Merit: 250
February 14, 2013, 03:08:18 AM
#26
Alright, I have this code:

Code:
require '../htdocs/config.php';
require 
'../util.php';

function 
update_req($reqid$status)
{
    
$query "
        UPDATE requests
        SET status='
$status'
        WHERE
            reqid='
$reqid'
            AND curr_type='RUC'
        "
;
    
do_query($query);
}

$query "
    SELECT
        requests.reqid AS reqid,
        uid,
        amount,
        addy
    FROM requests
    JOIN rucoin_requests
    ON requests.reqid=rucoin_requests.reqid
    WHERE
        req_type='WITHDR'
        AND amount > 0
        AND status='VERIFY'
        AND curr_type='RUC'
    "
;
$result do_query($query);
$rucoin connect_rucoin();
while (
$row mysql_fetch_assoc($result)) {
    
$reqid $row['reqid'];
    
$uid $row['uid'];
    
$amount $row['amount'];
    
$addy $row['addy'];

    if  (
$rucoin->getbalance('') >= 0)
    {
        
update_req($reqid'PROCES');
        
$rucoin->sendfrom(''$addy$amount);
        
update_req($reqid'FINAL');
    }
}
?>

And it is working perfectly all the way up to:

Code:
$rucoin->sendfrom('', $addy, $amount);

I believe I have a syntax error being fed to the jsonRPCClient as I know the $addy and $amount are both returning correct values, I have tested issuing the command by hand to rucoind so I know it supports the "sendfrom" function and is accessible yet I am receiving an HTTP 500 error from rucoind.

I am using the "$rucoin = connect_rucoin" function in various places to send calls to rucoind and retrieve information, all without error, but this last thing just does not seem to want to work.

Anyone have any ideas...?
hero member
Activity: 812
Merit: 1000
February 14, 2013, 12:39:54 AM
#25
not that netbeans is perfect, but you can use xdebug in that no problem, you don't have to use vim
hero member
Activity: 868
Merit: 1000
February 14, 2013, 12:07:37 AM
#24
Not sure what kind of tools you use to develop, but I just set up vim with xdebug on my personal development machine, and it works wonders:
https://bitcointalksearch.org/topic/quite-nice-debugging-tool-for-the-php-nerds-143923

I had an issue where some queries to get the current bitcoin price didn't work. So the usual method would be to make echo statements, and see where things went wrong, but then I installed this, and now I can step into functions, and execute code line by line, yay. I found the error I was chasing immediately, instead of using 30 minutes with echo statements. Smiley

I've never really used vim much, wasn't aware of the xdebug function, I always just code/edit in nano but sounds like vim might be worth taking a look at...

Vim has a very steep learning code, but you can do all kinds of awsome things with it, and that's not just for the showoff factor, but also for the practical factor. The cool thing is that there's no menus, no nothing on your screen, so people looking at you will think you're some kind of wizzard. Keeping a cheat sheet near the computer or on the computer is a nice thing. I am sure there's a lot of beginners guides. There's a lot of nice shortcuts that let you perform magic. You can do block editing, ie. vertical editing, you can make macros etc. and there exist a lot of plugins, with ctags you can even get autocomplete. So for the long run it rocks. Once you start mastering it, you will never go back.

sr. member
Activity: 294
Merit: 250
February 13, 2013, 11:48:08 PM
#23
Not sure what kind of tools you use to develop, but I just set up vim with xdebug on my personal development machine, and it works wonders:
https://bitcointalksearch.org/topic/quite-nice-debugging-tool-for-the-php-nerds-143923

I had an issue where some queries to get the current bitcoin price didn't work. So the usual method would be to make echo statements, and see where things went wrong, but then I installed this, and now I can step into functions, and execute code line by line, yay. I found the error I was chasing immediately, instead of using 30 minutes with echo statements. Smiley

I've never really used vim much, wasn't aware of the xdebug function, I always just code/edit in nano but sounds like vim might be worth taking a look at...
hero member
Activity: 868
Merit: 1000
February 13, 2013, 11:43:29 PM
#22
Not sure what kind of tools you use to develop, but I just set up vim with xdebug on my personal development machine, and it works wonders:
https://bitcointalksearch.org/topic/quite-nice-debugging-tool-for-the-php-nerds-143923

I had an issue where some queries to get the current bitcoin price didn't work. So the usual method would be to make echo statements, and see where things went wrong, but then I installed this, and now I can step into functions, and execute code line by line, yay. I found the error I was chasing immediately, instead of using 30 minutes with echo statements. Smiley
hero member
Activity: 812
Merit: 1000
February 13, 2013, 11:41:28 PM
#21
Aah, the joys of PHP and echo'ing SQL statements carefully crafted by hand Cheesy

yeah these days i'm more likely to be using codeigniter's $db->last_query() function after having it constructed for me Cheesy
sr. member
Activity: 294
Merit: 250
February 13, 2013, 11:30:42 PM
#20
Ok, that code is working perfectly now. It connects, queries and writes to the db exactly as it should (thanks everyone!!!).

Now, if anyone is interested, I am having a new problem.

Here is the problematic code:
Code:
require '../htdocs/config.php';
require 
'../util.php';

function 
update_req($reqid$status)
{
    
$query "
        UPDATE requests
        SET status='
$status'
        WHERE
            reqid='
$reqid'
            AND curr_type='RUC'
        "
;
    
do_query($query);
}

$query "
    SELECT
        requests.reqid AS reqid,
        uid,
        amount,
        addy
    FROM requests
    JOIN rucoin_requests
    ON requests.reqid=rucoin_requests.reqid
    WHERE
        req_type='WITHDR'
        AND amount > '0'
        AND status='VERIFY'
        AND curr_type='RUC'
    "
;
$result do_query($query);
$rucoin connect_rucoin();
while (
$row mysql_fetch_assoc($result)) {
    
$reqid $row['reqid'];
    
$uid $row['uid'];
    
$amount $row['amount'];
    
$addy $row['addy'];

    if (
gmp_cmp($rucoin->getbalance(""), $amount) >= '0')
    {
        
update_req($reqid"PROCES");
        
$rucoin->sendfrom(""$addy$amount);
        
update_req($reqid"FINAL");
    }
}

?>

This code should check the "requests" table for "req_type='WITHDR'" with amounts greater than '0' with "status='verify'" and "curr_type='RUC'" and when it finds a transaction it copies the "reqid" and "addy" into a table called "rucoin_requests". This part of the code works.

From there the script should connect to rucoin, check to make sure the default account has enough funds to send the requested withdrawal amount. Upon verification of funds it should connect to the table "requests" and update the status to "PROCES". After that it should connect to rucoin and "sendfrom" the default ("") account the requested "$amount" to the "$addy" listed in the "rucoin_requests" table.

Right now, the code seems to be stuck after it updates the status to "verify" and copies the "reqid" and "addy" into the "rucoin_requests" table...
legendary
Activity: 1372
Merit: 1007
1davout
February 12, 2013, 04:49:54 PM
#19
Aah, the joys of PHP and echo'ing SQL statements carefully crafted by hand Cheesy
legendary
Activity: 1904
Merit: 1037
Trusted Bitcoiner
February 12, 2013, 04:31:24 PM
#18
When I run:
Code:
INSERT INTO requests (req_type, uid, amount, curr_type) VALUES ('DEPOS', '169', '1', 'LTC');
from mysql command line it works.

but for some reason when the page runs that script it doesn't work...

echo your query statement in php. then copy it to mysql and run it, there may be some small errors, like not adding quotes around strings.

try hard coding the values as a test and  do
Code:
echo mysql_error();
right after your do_query

and stop coding at 1am, it hurts!

produces no errors... odd...

so its working with hard coded values?
sr. member
Activity: 294
Merit: 250
February 12, 2013, 07:51:02 AM
#17
When I run:
Code:
INSERT INTO requests (req_type, uid, amount, curr_type) VALUES ('DEPOS', '169', '1', 'LTC');
from mysql command line it works.

but for some reason when the page runs that script it doesn't work...

echo your query statement in php. then copy it to mysql and run it, there may be some small errors, like not adding quotes around strings.

try hard coding the values as a test and  do
Code:
echo mysql_error();
right after your do_query

and stop coding at 1am, it hurts!

produces no errors... odd...
legendary
Activity: 1904
Merit: 1037
Trusted Bitcoiner
February 12, 2013, 02:52:37 AM
#16
When I run:
Code:
INSERT INTO requests (req_type, uid, amount, curr_type) VALUES ('DEPOS', '169', '1', 'LTC');
from mysql command line it works.

but for some reason when the page runs that script it doesn't work...

echo your query statement in php. then copy it to mysql and run it, there may be some small errors, like not adding quotes around strings.

try hard coding the values as a test and  do
Code:
echo mysql_error();
right after your do_query

and stop coding at 1am, it hurts!
hero member
Activity: 868
Merit: 1000
February 12, 2013, 02:44:50 AM
#15
When I run:
Code:
INSERT INTO requests (req_type, uid, amount, curr_type) VALUES ('DEPOS', '169', '1', 'LTC');
from mysql command line it works.

but for some reason when the page runs that script it doesn't work...

echo your query statement in php. then copy it to mysql and run it, there may be some small errors, like not adding quotes around strings.
sr. member
Activity: 294
Merit: 250
February 12, 2013, 02:38:18 AM
#14
Ok, thank you for all the answers guys! The errors are gone but it's not updating my database properly. I believe it has to do with the call to the "requests" table not functioning properly as the requests table reports as "empty set" in mysql...

to debug it, echo the mysql queries and run them by hand through mysql and weed out the errors.

adam, thanks for the input, brain works badly when it's late.
I know the feeling   Tongue
weird its complaining about gmp_cmp() when its the do_query that failed.


what is this "connect_bitcoin();"

is their a php lib for managing a bitcoin wallet?

lol, connect_bitcoin is a separate function that calls to a script that connects to the servers bitcoin port, it is used in tandem with other scripts to communicate with the daemon and return the results of various rpc functions depending on the script it is being used in. What I'm doing is I've built an intersango installation, removed the "GBP" stuff, have added litecoin and bitcoin to the code, downloaded the "exper" branch from intersango's gitorious, imported the new database from exper which contains the "baskets" table where I added litecoin and bitcoin, now just trying to get it to update the db properly...
sr. member
Activity: 294
Merit: 250
February 12, 2013, 02:31:26 AM
#13
When I run:
Code:
INSERT INTO requests (req_type, uid, amount, curr_type) VALUES ('DEPOS', '169', '1', 'LTC');
from mysql command line it works.

but for some reason when the page runs that script it doesn't work...
legendary
Activity: 1904
Merit: 1037
Trusted Bitcoiner
February 12, 2013, 02:23:00 AM
#12
Ok, thank you for all the answers guys! The errors are gone but it's not updating my database properly. I believe it has to do with the call to the "requests" table not functioning properly as the requests table reports as "empty set" in mysql...

to debug it, echo the mysql queries and run them by hand through mysql and weed out the errors.

adam, thanks for the input, brain works badly when it's late.
I know the feeling   Tongue
weird its complaining about gmp_cmp() when its the do_query that failed.


what is this "connect_bitcoin();"

is their a php lib for managing a bitcoin wallet?
hero member
Activity: 868
Merit: 1000
February 12, 2013, 02:12:30 AM
#11
Ok, thank you for all the answers guys! The errors are gone but it's not updating my database properly. I believe it has to do with the call to the "requests" table not functioning properly as the requests table reports as "empty set" in mysql...

to debug it, echo the mysql queries and run them by hand through mysql and weed out the errors.

adam, thanks for the input, brain works badly when it's late.
sr. member
Activity: 294
Merit: 250
February 12, 2013, 01:51:45 AM
#10
Ok, thank you for all the answers guys! The errors are gone but it's not updating my database properly. I believe it has to do with the call to the "requests" table not functioning properly as the requests table reports as "empty set" in mysql...
Pages:
Jump to: