PayPal IPN MADNESS!!!

blondegeek

Baseband Member
Messages
23
So. I've been getting my webstore all PayPal savvy and everything and I'm only finding one problem with my Instant Payment Notification handler and it doesn't even have to do with what PayPal posts to the page (i think...)

Here's the bit I'm having trouble with (if you need the rest for reference let me know)
PHP:
if ($txn_type == "cart"){
    $strQuery = "insert into customers(paymentstatus,email,first_name,last_name,street,city,state,zip,country,mc_gross,mc_fee,memo,paymenttype,paymentdate,txnid,num_items,pendingreason,reasoncode,tax,datecreation) values ('".$payment_status."','".$payer_email."','".$first_name."','".$last_name."','".$address_street."','".$address_city."','".$address_state."','".$address_zip."','".$address_country."','".$mc_gross."','".$mc_fee."','".$memo."','".$payment_type."','".$payment_date."','".$txn_id."','".$num_cart_items."','".$pending_reason."','".$reason_code."','".$tax."','".$fecha."')";

     $result = mysql_query($strQuery) or die("Cart - customers, Query failed:<br>" . mysql_error() . "<br>" . mysql_errno());
     for ($i = 1; $i <= $num_cart_items; $i++) {
         $itemname = "item_name".$i;
         $itemnumber = "item_number".$i;
         $quantity = "quantity".$i;

         $strQuery2 = "insert into purchases(txnid,item_number,item_name,quantity,invoice,custom) values ('".$txn_id."','".$_POST[$itemnumber]."','".$_POST[$itemname]."','".$_POST[$quantity]."','".$invoice."','".$custom."')";
         $result = mysql_query($strQuery2) or die("Cart - purchases, Query failed:<br>" . mysql_error() . "<br>" . mysql_errno());
		
	$products = "SELECT * FROM `products` WHERE `prod_id` = '".$_POST[$itemnumber]."'  ";
	$strQuery3 = mysql_query($products);
		while($change_stock = mysql_fetch_assoc($strQuery3)) {
			$stock      = stripslashes( $change_stock['stock'] );
			
			}
			$new_stock = $stock - $_POST[$quantity];
$strQuery4 = "UPDATE `products` SET `stock` = '".$_POST[$newstock]."' WHERE `prod_id` = '".$_POST[$itemnumber]."'  ";
		mysql_query($strQuery4);
		
     }
  }

Everything's fine when I'm trying to insert the new data. It's trying to update my stock that is the problem. When the form mails the variable strQuery4 to me it says
UPDATE `products` SET `stock` = '' WHERE `prod_id` = '02020202'

At first I'm like "Yay!" because it got the prod_id of the item to show up but I can't get the newstock number I want it to use to replace the old stock number.

Being that I'm very very very new to php I wouldn't be surprised if it is some syntax error but at the same time the handler says everything is fine and dandy. Any clues?

Thanks and sorry for the lengthy post :)
 
the problem appear to be that the variable $_POST['newstock'] doesn't have a value,

I think that yur query for this is meant to be...

Code:
$strQuery4 = "UPDATE `products` SET `stock` = '".$new_stock."' WHERE `prod_id` = '".$_POST[$itemnumber]."'  ";
 
Ah, the one thing I didn't try. It always comes to that. Thank you! (you know, root, you're usually the first and only person to answer my posts and with the correct solution too)

Turns out there were two problems: 1) the problem that was solved above 2) prod_id is not a column in my database but pro_id is. It's always the simple things :)

Thanks again!
 
Back
Top Bottom