JoshTutt Posted November 12, 2014 Share Posted November 12, 2014 (edited) Notice: Undefined index: category in C:\xampp\htdocs\content\cron\check_deposits.php on line 18 Notice: Undefined index: confirmations in C:\xampp\htdocs\content\cron\check_deposits.php on line 19 Notice: Undefined index: address in C:\xampp\htdocs\content\cron\check_deposits.php on line 20 Notice: Undefined index: amount in C:\xampp\htdocs\content\cron\check_deposits.php on line 21 Notice: Undefined index: txid in C:\xampp\htdocs\content\cron\check_deposits.php on line 22 <?php // CRON must be running every minute! $included=true; include '../../inc/db-conf.php'; include '../../inc/wallet_driver.php'; $wallet=new jsonRPCClient($driver_login); include '../../inc/functions.php'; $deposits=mysql_query("SELECT * FROM `deposits`"); while ($dp=mysql_fetch_array($deposits)) { $received=0; $txid=''; $txs=$wallet->listtransactions('',2000); $txs=array_reverse($txs); foreach ($txs as $tx) { if ($tx['category']!='receive') continue; if ($tx['confirmations']<1) continue; if ($tx['address']!=$dp['address']) continue; $received=$tx['amount']; $txid=$tx['txid']; break; } if ($received<0.00000001) continue; $txid=($txid=='')?'[unknown]':$txid; if ($dp['received']==1) { mysql_query("UPDATE `deposits` SET `confirmations`=`confirmations`+1 WHERE `id`=$dp[id] LIMIT 1"); if (++$dp['confirmations']>=6) { $delExed=false; do { $delExed=mysql_query("DELETE FROM `deposits` WHERE `id`=$dp[id] LIMIT 1"); } while ($delExed==false); mysql_query("UPDATE `players` SET `balance`=TRUNCATE(ROUND((`balance`+$received),9), WHERE `id`=$dp[player_id] LIMIT 1"); mysql_query("INSERT INTO `transactions` (`player_id`,`amount`,`txid`) VALUES ($dp[player_id],$dp[amount],'$dp[txid]')"); } continue; } mysql_query("UPDATE `deposits` SET `received`=1,`amount`=$received,`txid`='$txid' WHERE `id`=$dp[id] LIMIT 1"); } mysql_query("DELETE FROM `deposits` WHERE `time_generated`<NOW()-INTERVAL 7 DAY"); ?> For some reason I am getting all these errors, and I cannot figure out why? Is there anyone out there that thinks they know what is wrong with it? check_deposits.php Edited November 12, 2014 by JoshTutt Quote Link to comment Share on other sites More sharing options...
NotionCommotion Posted November 12, 2014 Share Posted November 12, 2014 if ($tx['category']!='receive') continue; Notice: Undefined index: category in C:\xampp\htdocs\content\cron\check_deposits.php on line 18 $tx does not have the element 'category'. When you get these errors/notices, back up a bit. Use either var_dump($txs) or my favorite echo('<pre>'.print_r($txs,1).'</pre>');. Is the array what you expected? Quote Link to comment Share on other sites More sharing options...
Ch0cu3r Posted November 12, 2014 Share Posted November 12, 2014 You may need to set the second argument for array_reverse to true in order for the keys to be preserved. $txs=array_reverse($txs, true); Quote Link to comment Share on other sites More sharing options...
bsmither Posted November 12, 2014 Share Posted November 12, 2014 An "Undefined index" notice is just, according to one school of programming, an advisory that the programmer should declare/load the variables that are going to be used. Then, if you still get these 'undefined' notices, then you have a good idea that a variable that you intended to use is misspelled. For example: $arrParams = array('color' => 'Red', 'size' => "Large"); echo $arrParams['colour']; This will generate an undefined index notice because 'colour' is not the same as the intended 'color'. Quote Link to comment Share on other sites More sharing options...
NotionCommotion Posted November 12, 2014 Share Posted November 12, 2014 You may need to set the second argument for array_reverse to true in order for the keys to be preserved. $txs=array_reverse($txs, true); I am sure you are correct, however, I always say "look at what the server is telling you by using var_dump or print_r (and without saying, error detection)". I've posted a dozen similar replies, and have not heard once that it was of any help. Shouldn't (especially beginners) be doing this often? Quote Link to comment Share on other sites More sharing options...
Barand Posted November 12, 2014 Share Posted November 12, 2014 I am sure you are correct, however, I always say "look at what the server is telling you by using var_dump or print_r (and without saying, error detection)". I've posted a dozen similar replies, and have not heard once that it was of any help. Shouldn't (especially beginners) be doing this often? Debugging - isn't that what they think we exist for? Quote Link to comment Share on other sites More sharing options...
NotionCommotion Posted November 13, 2014 Share Posted November 13, 2014 Debugging - isn't that what they think we exist for? Guess so, but they are missing out on some fun! Quote Link to comment Share on other sites More sharing options...
JoshTutt Posted November 14, 2014 Author Share Posted November 14, 2014 (edited) This is the output I get when I use: echo('<pre>'.print_r($txs,1).'</pre>');. Output: Array ( [transactions] => Array ( [0] => Array ( [amount] => 8.131E-5 [blockhash] => 00000000000000001bb164ff85fe78f5f54bde00d4462d8bef19f96421334673 [address] => 1HJqsE5CoPnVSPvQVKU4oPCVku47eu39kr [fee] => 0.0001 [txid] => 75c9ad12fdbe957ad3c98edfc02fa212dde0ca8e941373c82df5c545599936ce [label] => [time] => 1415703105 [category] => receive [confirmations] => -212 [blockindex] => 490989 [account] => ) [1] => Array ( [amount] => 1.5E-5 [blockhash] => 000000000000000001fd1bc6e7add41bbca9e4d77a43ccd430a144c70c08d985 [address] => 16GttENVpxmq1oZjnP5TkLWDrwi3HBa1iu [fee] => 0.0001 [txid] => 29420d9a380df6546920a7cd5da5f9750219ef8e1102f2194547a38323e6dfd7 [label] => [time] => 1415453123 [category] => receive [confirmations] => -633 [blockindex] => 489453 [account] => ) [2] => Array ( [amount] => -5.7E-5 [blockhash] => 000000000000000001fd1bc6e7add41bbca9e4d77a43ccd430a144c70c08d985 [address] => 13ViX8aGoMMnA3JXnP8vL4P3RLFWPVP4Zw [fee] => 0.0001 [txid] => 29420d9a380df6546920a7cd5da5f9750219ef8e1102f2194547a38323e6dfd7 [label] => [time] => 1415453123 [category] => send [confirmations] => -633 [blockindex] => 489453 [account] => ) [3] => Array ( [amount] => -6.0E-5 [blockhash] => 000000000000000001fd1bc6e7add41bbca9e4d77a43ccd430a144c70c08d985 [address] => 16GttENVpxmq1oZjnP5TkLWDrwi3HBa1iu [fee] => 0.0001 [txid] => 29420d9a380df6546920a7cd5da5f9750219ef8e1102f2194547a38323e6dfd7 [label] => [time] => 1415453123 [category] => send [confirmations] => -633 [blockindex] => 489453 [account] => ) [4] => Array ( [amount] => -5.5E-5 [blockhash] => 000000000000000001fd1bc6e7add41bbca9e4d77a43ccd430a144c70c08d985 [address] => 14DxVjNkuEWruF9bQpY9xym7Vs4GuoYe13 [fee] => 0.0001 [txid] => 29420d9a380df6546920a7cd5da5f9750219ef8e1102f2194547a38323e6dfd7 [label] => [time] => 1415453123 [category] => send [confirmations] => -633 [blockindex] => 489453 [account] => ) [5] => Array ( [amount] => 5.5E-5 [blockhash] => 00000000000000000cfa9ee58b91b27629dd8607ff838cb1880e871745f6fda7 [address] => 14DxVjNkuEWruF9bQpY9xym7Vs4GuoYe13 [fee] => 0.0001 [txid] => 03fcddb0bbd3adf5dae20f6f67840e3b9acf8305bd446e31a2690e3ae7d71def [label] => [time] => 1415431105 [category] => receive [confirmations] => -674 [blockindex] => 486258 [account] => ) [6] => Array ( [amount] => 6.0E-5 [blockhash] => 000000000000000010b72e16dc753ccd2d9cfc5d03846748685d9374abd03c89 [address] => 16GttENVpxmq1oZjnP5TkLWDrwi3HBa1iu [fee] => 0.0001 [txid] => 296dea431d71e23a4015f2a9e2e91abd9a500fbbef266de5de8d5020af6dd566 [label] => [time] => 1415246423 [category] => receive [confirmations] => -1003 [blockindex] => 489250 [account] => ) [7] => Array ( [amount] => 5.7E-5 [blockhash] => 0000000000000000001436c6d5f9118a6a2f00087629dbf6fac3e5cd9672f0b6 [address] => 13ViX8aGoMMnA3JXnP8vL4P3RLFWPVP4Zw [fee] => 0.0001 [txid] => b4c517c2b82468f8484a8bac47aeb88d7386c3d43acfe8b592cbf367cb9c0d3c [label] => [time] => 1415177200 [category] => receive [confirmations] => -1092 [blockindex] => 486057 [account] => ) ) [lastblock] => 00000000000000000db5d7c653732396fa7345bb4f97cbab73720e29d9c0b7bd ) Edited November 14, 2014 by JoshTutt Quote Link to comment Share on other sites More sharing options...
JoshTutt Posted November 14, 2014 Author Share Posted November 14, 2014 Okay so this is the problem I have been suffering with for the past 2 weeks: Notice: Undefined index: category in C:\xampp\htdocs\content\cron\check_deposits.php on line 18 $deposits=mysql_query("SELECT * FROM `deposits`"); while ($dp=mysql_fetch_array($deposits)) { $received=0; $txid=''; $txs=$wallet->listtransactions('',2000); $txss=array_reverse($txs, true); foreach ($txss as $tx) { if ($tx['category']!='receive') continue; if ($tx['confirmations']<1) continue; if ($tx['address']!=$dp['address']) continue; $received=$tx['amount']; $txid=$tx['txid']; break; } The output array using: <? echo('<pre>'.print_r($txs,1).'</pre>'); ?> is: Array ( [lastblock] => 00000000000000000e453b7ab34fa8209f838e56f1205ac289d9e071b79351d0 [transactions] => Array ( [0] => Array ( [amount] => 8.131E-5 [blockhash] => 00000000000000001bb164ff85fe78f5f54bde00d4462d8bef19f96421334673 [address] => 1HJqsE5CoPnVSPvQVKU4oPCVku47eu39kr [fee] => 0.0001 [txid] => 75c9ad12fdbe957ad3c98edfc02fa212dde0ca8e941373c82df5c545599936ce [label] => [time] => 1415703105 [category] => receive [confirmations] => -381 [blockindex] => 490989 [account] => ) [1] => Array ( [amount] => 1.5E-5 [blockhash] => 000000000000000001fd1bc6e7add41bbca9e4d77a43ccd430a144c70c08d985 [address] => 16GttENVpxmq1oZjnP5TkLWDrwi3HBa1iu [fee] => 0.0001 [txid] => 29420d9a380df6546920a7cd5da5f9750219ef8e1102f2194547a38323e6dfd7 [label] => [time] => 1415453123 [category] => receive [confirmations] => -802 [blockindex] => 489453 [account] => ) So if I use: <? $list = $tx['0']; echo('<pre>'.print_r($list,1).'</pre>'); ?> I get the output: Array. So what I have come to is that because they are listed [0], [1] is causing the problem. How should I go about extracting the value of what is in the array [0] [1] and so on? Quote Link to comment Share on other sites More sharing options...
NotionCommotion Posted November 14, 2014 Share Posted November 14, 2014 (edited) This is the output I get when I use: echo('<pre>'.print_r($txs,1).'</pre>');. Ah, you've redeemed my faith in Newbies! So I condensed the output to make it simpler. It contains two primary elements: transactions which is in turn an unassociated array containing (7) associated arrays, and lastblock which is a string. When you apply the foreach on it, you or iterating over these two elements, yet it is obviously that you need to iterate over the transactions array (and when you do, $tx will be one of those 7 associated arrays, and sure enough category, confirmations, address, amount, and txid are all there - at least I hope so because I didn't check While this didn't not specifically solve your issue, it gives you the clues to quickly figure it out. Array ( [transactions] => Array ([0] => Array(...),[1] => Array(...),[2] => Array(...),...,[7] => Array(...)) [lastblock] => 00000000000000000db5d7c653732396fa7345bb4f97cbab73720e29d9c0b7bd ) Edited November 14, 2014 by NotionCommotion Quote Link to comment Share on other sites More sharing options...
Recommended Posts
Join the conversation
You can post now and register later. If you have an account, sign in now to post with your account.