Jump to content


Photo

txn_id check and still twice updated why?


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

#1 statusquo

statusquo

    Newbie

  • Members
  • Pip
  • 5 posts

Posted 23 January 2003 - 03:48 PM

Hey all,
I altered my script from yesterday to check for the txn_id. What it's supposed to do now is 1) look for txn_id. if it exists, go to another page or update my databases if it doesn't exist.

What happens now is my database gets updated on a new transaction at paypal when I hit the pay button. When I hit continue afterwards, I am redirected to another page (txn_id must have been found), but it still updates the tables a second time. Can anyone see what I am doing wrong please?

Thank you

-------altered php snippet------



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

$paypal_query = "SELECT txn_id from $table4";
$result = mysql_db_query ($dbase, $paypal_query, $con) or die (mysql_error());

$ppq = mysql_fetch_array($result);
while ($ppq = mysql_fetch_array($result)) {
if ($txn_id == $ppq[txn_id]) {
header ("location: testpp.php");
} else {
$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_arra ($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--;
}

// 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());

$paypal_update_query = "INSERT INTO $table4 (receiver_email,business,item_name,item_id,tickets_bought,invoice,custom,payment_status,pending_reason,payment_date,payment_gross,payment_fee,txn_id,txn_type,first_name,last_name, email,user_id_pp,payer_status,payment_type,notify_version) VALUES (\"$receiver_email\",\"$business\",\"$item_name\",\"$item_id\",\"$quantity\",\"$invoice\",\"$custom\",\"$payment_status\",\"$pending_reason\",\"$payment_date\",\"$payment_gross\",\"$payment_fee\",\"$txn_id\",\"$txn_type\",\"$first_name\",\"$last_name\",\"$email\",\"$user_id_pp\",\"$payer_status\",\"$payment_type\",\"$notify_version\")";

mysql_db_query($dbase, $paypal_update_query, $con) or die (mysql_error());

}

}


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

#2 EliteWeaver

EliteWeaver

    Junior Member

  • Members
  • 239 posts

Posted 23 January 2003 - 05:58 PM

Hhmmm, I can't be bothered to read all that but I did notice you have a lot of sql
queries and are going the long way around!

Here is how I would do it:

$txn_check = mysql_query("SELECT txn_id FROM $table4 WHERE txn_id = '$txn_id'");
$txn_exist = mysql_num_rows($txn_check);

if ($txn_exist) {

//* OK WE FOUND IT IGNORE & REDIRCT!

} else {

//* UPDATE THE DB & PAT THE DOG!

}

BTW: Looking at your { bracket placements } your script is still
processing after the redirect, so I would also check your syntax!


Good luck,

Marcus Cicero
EliteWeaver UK


#3 statusquo

statusquo

    Newbie

  • Members
  • Pip
  • 5 posts

Posted 23 January 2003 - 07:46 PM

Thank you Marcus,
I will try it that way...looks a lot simpler and straighter toward the objective....which is to update the db and pat the dog hehehe.

I'll let you know how it goes.

Thanks again.

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




0 user(s) are reading this topic

0 members, 0 guests, 0 anonymous users