Multiple updates

Apologies for my lack of scripting skills. I’m trying to adapt a PayPal IPN script to update several tables in one go.

This script works fine: $strQuery2 =

“UPDATE user_usr
SET amt_paid_usr='”.$mc_gross.“’
, paypal_usr='”.$txn_id.“’
, paymentdate_usr='”.$fecha.“’
WHERE invoice_usr='”.$custom.“'”;
"

$result = mysql_query($strQuery2) or die(“Subscription - paypal_subscription_info, Query failed:<br>” . mysql_error() . “<br>” . mysql_errno());

When adding a second query it fails:

“UPDATE user_usr
SET amt_paid_usr='”.$mc_gross.“’
, paypal_usr='”.$txn_id.“’
, paymentdate_usr='”.$fecha.“’
WHERE invoice_usr='”.$custom.“'”;

“UPDATE transactions
SET amt_paid_trn='”.$mc_gross.“’
, paypal_usr='”.$txn_id.“’
, paymentdate_trn='”.$fecha.“’
WHERE '”.$item_name.“’
LIKE ‘%G%’ AND gifter_trn='”.$custom.“'”;

$result = mysql_query($strQuery2) or die(“Subscription - paypal_subscription_info, Query failed:<br>” . mysql_error() . “<br>” . mysql_errno());

I also tried to enclose in quotes rather than two separate sets:

$strQuery2 = “UPDATE user_usr
SET amt_paid_usr='”.$mc_gross.“’
, paypal_usr='”.$txn_id.“’
, paymentdate_usr='”.$fecha.“’
WHERE invoice_usr='”.$custom."';

UPDATE transactions
SET amt_paid_trn=‘“.$mc_gross.”’
, paypal_usr=‘“.$txn_id.”’
, paymentdate_trn=‘“.$fecha.”’
WHERE ‘“.$item_name.”’ LIKE ‘%G%’
AND gifter_trn=‘“.$custom.”’";

$result = mysql_query($strQuery2) or die(“Subscription - paypal_subscription_info, Query failed:<br>” . mysql_error() . “<br>” . mysql_errno());

[fphp]mysql_query[/fphp] can run only 1 query at a time.

and you should probably be using a database transaction for this process

:slight_smile:

If your db doesn’t support transactions then you can undo the updates programatically from the application in the unlikely scenario an error occurs preventing all the updates from completing.