PHP variable not loading more than once?

I have a variable that contains post data:

$ttransid = $_POST["t_transid"];

I then connect to a database and pull info from the row that corresponds with $ttransid. This works fine.

A paypal transaction is then made, if the payment is successful the database is updated with the payment info - This works.

Now my code tries to update the database and remove stock based on the original $ttransid variable at the beginning.

 $querysub = "UPDATE ibn_table SET iname = iname - 1 WHERE itransaction_id='$ttransid'";
        if(!mysql_query($querysub))
        {
            //mysql error..!
        }

The database is updated, but only where itransaction_id is blank, suggesting $ttransid is empty. Although it was called and used correctly at the beginning of the code.

Any ideas?

Upvotes: 0

Views: 63

Answers (2)

user3356107
user3356107

Reputation: 11

At starting point before going to the paypal payment page just keep the $transid [Availabe in POST data] in to the session then after payment success, update db with session transid.

After this process just destroy the transid from the session.

Sure it will work.

Upvotes: 0

Awais Qarni
Awais Qarni

Reputation: 18006

This is because next time your page is hit, the $_POST is empty so there is no $_POST["t_transid"]. So when you assign

 $ttransid = $_POST["t_transid"];

It gets empty and update empty string. I suggest you to save that post variable value in your database or in session so you can use that latter.

Upvotes: 3

Related Questions