Paypal IPN - $5 for quick solution!
03-13-2008, 05:13 PM
|
Paypal IPN - $5 for quick solution!
|
Posts: 842
Name: Rich Powell
Location: United Kingdom
|
I will send $5 to anyone who can identify WHY this erroring. Cannot give specific error because Display_errors = Off and don't really want to restart machine to enable it due to sites being on it.
My first question is. Is this code correct? I'm assuming if the payment is valid but not complete it is an echeque so the product they have ordered is set to "waiting".
Ther sneaky error is in this extract of the code somewhere which is causing a blank page. $5 for anyone who can fix it.
PHP Code:
while (!feof($fp)) { $res = fgets ($fp, 1024); if (strcmp ($res, "VERIFIED") == 0) { if ($payment_status != "completed") or ($receiver_email != $actual_email) or ($payment_amount != $actual_amount) { mysql_query("insert into `payment` ('', '$item_name', '$payment_status', '$payment_amount', '$payment_currency', '$txn_id', '$receiver_email', '$payer_email', '$quantity', '$user_id', NOW())"); mysql_query("update codes set `sold_date` = NOW(), `sold_user` = $user_id, `paid` = 'waiting' where `card_type` = '$card_type' and `sold_user` = 0 and `paid` = '' limit $quantity"); } else {
mysql_query("insert into payment ('', $item_name, $payment_status, $payment_amount, $payment_currency, $txn_id, $receiver_email, $payer_email, $quantity, $user_id, NOW())"); $waitingcodes = mysql_num_rows(mysql_query("select * from codes where `card_type` = '$card_type' and `sold_user` = $user_id and `paid` = 'waiting'")); if($waitingcodes > 0){ mysql_query("update codes set `paid` = 'complete' where `card_type` = '$card_type' `sold_user` = $user_id and paid = 'complete' limit $quantity");
$waitingcodesnew = mysql_num_rows(mysql_query("select * from codes where `card_type` = '$card_type' and `sold_user` = $user_id and `paid` = 'waiting'"));
if($waitingcodesnew > 0){ $newquantity = 0; } else { $newquantity = $waitingcodes - $waitingcodesnew; } } else { $newquantity = $quantity; } if($newquantity > 0){ mysql_query("update `codes` set `sold_date` = NOW(), `sold_user` = $user_id, paid = 'complete' where `sold_user` = 0 and paid = '' limit $newquantity"); } } } elseif (strcmp ($res, "INVALID") == 0) { mysql_query("insert into payments ('', $item_name, $payment_status, $payment_amount, $payment_currency, $txn_id, $receiver_email, $payer_email, $quantity, $user_id, NOW())"); } } } fclose ($fp); } print "hello";
It never seems to reach hello 
Last edited by Galaxian; 03-13-2008 at 05:16 PM..
|
|
|
|
03-13-2008, 05:23 PM
|
Re: Paypal IPN - $5 for quick solution!
|
Posts: 2,815
Name: Matt
Location: Irvine, CA
|
Your code is a bit messy.. you should start indenting the body of your if statements and loops. At first glance your insert queries don't seem to be using correct syntax. I'm not sure if the way you are doing it works or not but generally an insert looks more like this:
Code:
INSERT INTO tbl_name (`column1` , `column2`) VALUES( 'value1' , 'value2');
What you have is this:
Code:
INSERT INTO tbl_name ('value1' , 'value2');
I may be wrong but that was the first thing that caught my eye. Without an error message its kind of hard to pick out where the problem is. I suggest turning error messages on and using @ to suppress warnings and errors
PHP Code:
$result = mysql_query('BAD QUERY');
mysql_fetch_array($result, MYSQL_ASSOC) //will generate an error message without a valid $result
@mysql_fetch_array($result, MYSQL_ASSOC) //will not
Last edited by NullPointer; 03-13-2008 at 05:28 PM..
|
|
|
|
03-13-2008, 05:25 PM
|
Re: Paypal IPN - $5 for quick solution!
|
Posts: 1,228
|
I think you have too many closing braces. I indented your code and the last two braces didn't seem like they belonged.
PHP Code:
} fclose ($fp); }
Last edited by VirtuosiMedia; 03-13-2008 at 05:26 PM..
|
|
|
|
03-13-2008, 05:35 PM
|
Re: Paypal IPN - $5 for quick solution!
|
Posts: 842
Name: Rich Powell
Location: United Kingdom
|
Thanks to both of you. However the error is still not fixed. I will now include more of the code. I think maybe the 2 braces you pointed out belong in this.
PHP Code:
if (!$fp) { echo "There was a problem connecting to the IPN server, check your port status."; } else { fputs ($fp, $header . $req); while (!feof($fp)) { $res = fgets ($fp, 1024); if (strcmp ($res, "VERIFIED") == 0) { if ($payment_status != "completed") or ($receiver_email != $actual_email) or ($payment_amount != $actual_amount) { mysql_query("insert into `payment` values ('', '$item_name', '$payment_status', '$payment_amount', '$payment_currency', '$txn_id', '$receiver_email', '$payer_email', '$quantity', '$user_id', NOW())"); mysql_query("update codes set `sold_date` = NOW(), `sold_user` = $user_id, `paid` = 'waiting' where `card_type` = '$card_type' and `sold_user` = 0 and `paid` = '' limit $quantity"); } else {
mysql_query("insert into payment values ('', $item_name, $payment_status, $payment_amount, $payment_currency, $txn_id, $receiver_email, $payer_email, $quantity, $user_id, NOW())"); $waitingcodes = mysql_num_rows(mysql_query("select * from codes where `card_type` = '$card_type' and `sold_user` = $user_id and `paid` = 'waiting'")); if($waitingcodes > 0){ mysql_query("update codes set `paid` = 'complete' where `card_type` = '$card_type' `sold_user` = $user_id and paid = 'complete' limit $quantity");
$waitingcodesnew = mysql_num_rows(mysql_query("select * from codes where `card_type` = '$card_type' and `sold_user` = $user_id and `paid` = 'waiting'"));
if($waitingcodesnew > 0){ $newquantity = 0; } else { $newquantity = $waitingcodes - $waitingcodesnew; } } else { $newquantity = $quantity; } if($newquantity > 0){ mysql_query("update `codes` set `sold_date` = NOW(), `sold_user` = $user_id, paid = 'complete' where `sold_user` = 0 and paid = '' limit $newquantity"); } } } elseif (strcmp ($res, "INVALID") == 0) { mysql_query("insert into payment values ('', $item_name, $payment_status, $payment_amount, $payment_currency, $txn_id, $receiver_email, $payer_email, $quantity, $user_id, NOW())"); } } } fclose ($fp); } print "hello";
Last edited by Galaxian; 03-13-2008 at 05:36 PM..
|
|
|
|
03-13-2008, 05:38 PM
|
Re: Paypal IPN - $5 for quick solution!
|
Posts: 1,228
|
Check your while loop condition. You could be going into an infinite loop. That would keep it from displaying the hello at the bottom.
I didn't know feof is a function.
Last edited by VirtuosiMedia; 03-13-2008 at 05:47 PM..
|
|
|
|
03-13-2008, 05:41 PM
|
Re: Paypal IPN - $5 for quick solution!
|
Posts: 842
Name: Rich Powell
Location: United Kingdom
|
Page is status 'Done' in the browser with no apparent continuing communication with the server.
|
|
|
|
03-13-2008, 05:49 PM
|
Re: Paypal IPN - $5 for quick solution!
|
Posts: 1,228
|
Try changing this:
PHP Code:
if ($payment_status != "completed") or ($receiver_email != $actual_email) or ($payment_amount != $actual_amount){
to this:
PHP Code:
if (($payment_status != "completed") or ($receiver_email != $actual_email) or ($payment_amount != $actual_amount)){
Also, unless there's more code above, you still have an extra brace at the end.
Last edited by VirtuosiMedia; 03-13-2008 at 05:53 PM..
|
|
|
|
03-13-2008, 05:52 PM
|
Re: Paypal IPN - $5 for quick solution!
|
Posts: 2,815
Name: Matt
Location: Irvine, CA
|
Try running those queries through phpmyadmin if you can to see if they are valid. Seriously though.. testing code without error messages is not the best way to go about things.
|
|
|
|
03-13-2008, 05:55 PM
|
Re: Paypal IPN - $5 for quick solution!
|
Posts: 1,228
|
Quote:
Originally Posted by NullPointer
Try running those queries through phpmyadmin if you can to see if they are valid. Seriously though.. testing code without error messages is not the best way to go about things.
|
I agree on that...
|
|
|
|
03-13-2008, 06:08 PM
|
Re: Paypal IPN - $5 for quick solution!
|
Posts: 842
Name: Rich Powell
Location: United Kingdom
|
Quote:
Originally Posted by NullPointer
Try running those queries through phpmyadmin if you can to see if they are valid. Seriously though.. testing code without error messages is not the best way to go about things.
|
These queries aren't being executed yet because of the error. However even commenting out the queries produces no results.
I tried the code change NullPointer suggested but didn't have any effect.
As for the testing of it I've explained already.
|
|
|
|
03-13-2008, 06:11 PM
|
Re: Paypal IPN - $5 for quick solution!
|
Posts: 1,228
|
This probably won't get it to show if commenting out the queries doesn't do anything, but on some of your queries, you're using a ` instead of a '. That will send an error. Also have you tried echoing anything above the first conditional?
|
|
|
|
03-13-2008, 08:07 PM
|
Re: Paypal IPN - $5 for quick solution!
|
Posts: 842
Name: Rich Powell
Location: United Kingdom
|
Thanks for all your helps.
Fortunately I was able to fix the problem after restarting the server at a low peak time and change the error settings. I tell you - debugging is so much easier. Fixed it within a seconds. Apologies for wasting time.
|
|
|
|
|
« Reply to Paypal IPN - $5 for quick solution!
|
|
|
| Thread Tools |
Search this Thread |
|
|
|
Posting Rules
|
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts
HTML code is Off
|
|
|
|