Jump to content


Photo

for loop is doubling the quantity can anyone see


  • This topic is locked This topic is locked
3 replies to this topic

#1 statusquo

statusquo

    Newbie

  • Members
  • Pip
  • 5 posts

Posted 22 January 2003 - 04:05 PM

hey all.
I am receiving some $_POST info for my ipn script. The quantity comes in ok...I tested it with some print statements, but for some reason my for loop is doubling everything and updating my database two times more than it should. Here is a snippet of the script...maybe fresh eyes will see what I am missing. Thank you.
Oh....no errors in mysql statements in case that matters.
----php snippet all db info is included in an include ------


if (!strcmp ($reply, "VERIFIED")) {
if (!strcmp ($payment_status, "Completed")) {

$raffle_member_query = "SELECT * from $table1 WHERE user_id = \"$custom\"";
$result = mysql_db_query($dbase, $raffle_member_query, $con) or die (mysql_error());
// $rmq = mysql_fetch_array($result);

while ($rmq = mysql_fetch_array($result)) {

$user_id = $rmq[user_id];


}

$raffle_item_query = "SELECT * FROM $table2 where item_id = \"$item_id\"";
$result = mysql_db_query($dbase, $raffle_item_query, $con) or die(mysql_error());

while ($riq = mysql_fetch_array($result)) {

// $item_id1 = $riq[item_id];
$tickets_remaining = $riq[tickets_remaining];
// $tickets_remaining = $tickets_remaining - $quantity;
$starting_ticket = $riq[starting_ticket];
print ("Thank you for entering the $riq[item_name] raffle.<br> You have been entered $quantity times, giving you a $quantity in $riq[ticket_qty] chance of winning.<br>");
print ("We are going to start with ticket number $starting_ticket.<p>");
print ("We have $tickets_remaining tickets in the database.<p>");

}

for ($i = 1; $i <= $quantity; $i++) {





//for testing ticket number value
print ("you bought ticket number $starting_ticket<br>");

$enter_tickets_query = "INSERT INTO $table3(user_id, item_id, ticket_number) VALUES (\"$user_id\", \"$item_id\", \"$starting_ticket\")";
$result = mysql_db_query($dbase, $enter_tickets_query, $con) or die(mysql_error());
$starting_ticket++;
$tickets_remaining--;



}

// $tickets_remaining = $tickets_remaining - $quantity;
// for testing tickets remaining
print ("There are $tickets_remaining tickets remaining.");

$update_ticket_query = "UPDATE $table2 SET tickets_remaining=\"$tickets_remaining\" WHERE item_id='$item_id'";

$result = mysql_db_query($dbase, $update_ticket_query, $con) or die (mysql_error());

print ("<br>the next person to come along starts with ticket number $starting_ticket");
$update_starting_ticket_query = "UPDATE $table2 SET starting_ticket=\"$starting_ticket\" WHERE item_id='$item_id'";

$result = mysql_db_query($dbase, $update_starting_ticket_query, $con) or die (mysql_error());


I'm going as fast as I can type!!

#2 paypal_pb

paypal_pb

    Advanced Member

  • Members
  • 2,960 posts

Posted 22 January 2003 - 05:19 PM

It may be because the PayPal system retries the IPN until your web server returns a standard "200 OK" response.

You should definitely have a check in your script to prevent processing of the same txn_id more than once.

If PayPal is indeed POSTing more than once, it may indicate that your script is erroring after updating your DB.

Patrick Breitenbach
PayPal, Inc.
Dev Net: https://www.paypal.com/pdn

#3 statusquo

statusquo

    Newbie

  • Members
  • Pip
  • 5 posts

Posted 22 January 2003 - 09:06 PM

That occured to me and I kept an eye on my database as I went through the payment process at paypal.

Paypal sent the info to my ipn page (process_raffle.php) and I saw that my database was updated with the correct information. Then when I clicked continue at paypal, I was sent to process_raffle.php and the updates happened again when I arrived.

I guess I'll have to see if I can be carted off to a different page...perhaps a thank you page...and have the data variables follow the customer there and thank them for buying x number of y products ;)

I'm going as fast as I can type!!

#4 paypal_pb

paypal_pb

    Advanced Member

  • Members
  • 2,960 posts

Posted 22 January 2003 - 10:32 PM

You can set "return" to a different URL.

Patrick Breitenbach
PayPal, Inc.
Dev Net: https://www.paypal.com/pdn




0 user(s) are reading this topic

0 members, 0 guests, 0 anonymous users