George Botley Posted May 26, 2011 Share Posted May 26, 2011 Hello, I am developing a PayPal IPN interface which works fine, all is passed for verification and comes back 'VALID'. After validation with PayPal I update a users subscription and do the rest I want to do, but there is one thing really really irritating me. It seems to be that this one particular table in the database does not want to accept anything I throw at it through PHP. Here's the code: $query = "INSERT INTO `ipn_txn_logs` ( `date` , `payment_reason` , `pp_txn_id` , `pp_amount` , `pp_txn_charge` , `pp_txn_net_amount` , `ltj_txn_id` , `description` , `failsafe` , `member` ) VALUES ( '$date', 'subscribe', '$txn[txn_id]', '$txn[payment_amount]', '$txn[payment_charges]', '$txn[net_payment]', '$txn[custom]', '$desc', 'yes', '$fname $lname')"; $query = mysql_query($query); The array is set on the IPN return using all values from PayPal. The database will insert when all variable and arrays are left out of the INSERT and replaced with just the number 1.. I am unable to see a PHP error as it's done in the background after a PayPal response... is there anyway to collect this error? Also, any suggestions on this fault? George.[/code] Quote Link to comment https://forums.phpfreaks.com/topic/237555-php-array-into-database-paypal-ipn/ Share on other sites More sharing options...
silkfire Posted May 26, 2011 Share Posted May 26, 2011 Echo mysql_error you can try to save it to a text file. Try, mate. Quote Link to comment https://forums.phpfreaks.com/topic/237555-php-array-into-database-paypal-ipn/#findComment-1220741 Share on other sites More sharing options...
freelance84 Posted May 26, 2011 Share Posted May 26, 2011 You can send all the errors to an email in box... i made an IPN half a year ago and sent any errors to an inbox i set up specifically... [email protected]. just use php's mail() function Quote Link to comment https://forums.phpfreaks.com/topic/237555-php-array-into-database-paypal-ipn/#findComment-1220744 Share on other sites More sharing options...
xyph Posted May 26, 2011 Share Posted May 26, 2011 Try this $query = "INSERT INTO `ipn_txn_logs` ( `date` , `payment_reason` , `pp_txn_id` , `pp_amount` , `pp_txn_charge` , `pp_txn_net_amount` , `ltj_txn_id` , `description` , `failsafe` , `member` ) VALUES ( '$date', 'subscribe', '{$txn['txn_id']}', '{$txn['payment_amount']}', '{$txn['payment_charges']}', '{$txn['net_payment']}', '{$txn['custom']}', '$desc', 'yes', '$fname $lname')"; Quote Link to comment https://forums.phpfreaks.com/topic/237555-php-array-into-database-paypal-ipn/#findComment-1220756 Share on other sites More sharing options...
George Botley Posted May 27, 2011 Author Share Posted May 27, 2011 @freelance84 - Thanks for the tips on mail(). This has helped me now understand what the issues were. I never knew mail() could be used with an or command. Such a simple command to use as well. @xyph - Thanks, I will try this method.. Could you advise what the { } brackets actually do in this scenario? George. Quote Link to comment https://forums.phpfreaks.com/topic/237555-php-array-into-database-paypal-ipn/#findComment-1221238 Share on other sites More sharing options...
silkfire Posted May 27, 2011 Share Posted May 27, 2011 The brackets are actually not needed but they allow you to insert an array element within a string. You can also write $txn[payment_amount] (without inner quotes). Quote Link to comment https://forums.phpfreaks.com/topic/237555-php-array-into-database-paypal-ipn/#findComment-1221273 Share on other sites More sharing options...
George Botley Posted May 27, 2011 Author Share Posted May 27, 2011 Hello, Thank you for the explanation. I removed the curly brackets as I don't use them normally and so don't see why I should now change. That aside, with the mail() function, it was discovered the issue was relating to the $desc variables contents including an apostrophe. Thanks Guys. Quote Link to comment https://forums.phpfreaks.com/topic/237555-php-array-into-database-paypal-ipn/#findComment-1221286 Share on other sites More sharing options...
xyph Posted May 27, 2011 Share Posted May 27, 2011 Not using the curly braces SHOULD be wrong. In any language with a strict syntax it would be wrong. Don't use PHP's 'looseness' as an excuse to continue bad programming practices. From what I understand, that syntax will throw an E_NOTICE, as it will look for a constant with the name name first, not find it, and revert to the array key. This means if you define a constant with the same name as that key, things may start to explode. It's right in the manual - http://php.net/manual/en/language.types.array.php#language.types.array.foo-bar silkfire - avoid giving advice you aren't sure on. Quote Link to comment https://forums.phpfreaks.com/topic/237555-php-array-into-database-paypal-ipn/#findComment-1221339 Share on other sites More sharing options...
PFMaBiSmAd Posted May 27, 2011 Share Posted May 27, 2011 From what I understand, that syntax will throw an E_NOTICE ^^^ Not inside a string. Inside a string, $txn[txn_id] is parsed as though it was written as $txn['txn_id'] (I'm guessing if you were to look at the C code responsible for doing that, it probably looks like it was written by the clown act in a circus.) Outside of a string, php first evaluates the txn_id in $txn[txn_id] as a constant (which it should only do, then stop), then when it does not find a defined constant by that name and finishes with the error response code it assumes the programmer meant to enclose the index name in quotes and evaluates it as $txn['txn_id'] (more fun C code.) Quote Link to comment https://forums.phpfreaks.com/topic/237555-php-array-into-database-paypal-ipn/#findComment-1221393 Share on other sites More sharing options...
xyph Posted May 28, 2011 Share Posted May 28, 2011 Thanks for correcting me. I'm sure if you looked at anything involving double quotes and parsed string it would be pretty ugly. I avoid using them at all costs due to unnecessary overhead. Quote Link to comment https://forums.phpfreaks.com/topic/237555-php-array-into-database-paypal-ipn/#findComment-1221460 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.