Jump to content

PHP Array into Database (PayPal IPN)


George Botley

Recommended Posts

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]

Link to comment
Share on other sites

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')";

Link to comment
Share on other sites

@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.

Link to comment
Share on other sites

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.

Link to comment
Share on other sites

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.

Link to comment
Share on other sites

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.)

 

Link to comment
Share on other sites

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.

Link to comment
Share on other sites

This thread is more than a year old. Please don't revive it unless you have something important to add.

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.

Guest
Reply to this topic...

×   Pasted as rich text.   Restore formatting

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

×
×
  • Create New...

Important Information

We have placed cookies on your device to help make this website better. You can adjust your cookie settings, otherwise we'll assume you're okay to continue.