How you should probably do things
EDIT: Although I'm leaving this section here for now, I did make a false assumption about your process, so perhaps the next section is more beneficial
I have not used online payment systems in any of my own projects, but I just took a look at the PayPal docs to confirm something. The payment process seems to go like this:
- Get user order and payment details
- Pass payment details to Paypal
- Direct the user to the approval URL so that the user can approve the payment
- They are redirected to your site by PayPal, with a payment ID
- You then confirm the payment by querying PayPal with the payment ID
Most payment systems I've encountered online have had a similar process (from what I can see as an enduser). From what you're saying, it seems like you want to email the user and update your database at step 2, when you have not confirmed that a payment actually took place. I would suggest that instead, you perform the table update and email during step 5.
So wait until whatever payment system you are using has confirmed the order, and update at that point, as part of the same process in which you query PayPal to confirm the order (And you can make sure your actions depend on them having actually paid you!)
How you can do what you're asking to do
Going back to the guts of your question though. If you do want to execute your own server side code while directing them to the external system, I'd suggest you send an Ajax request when they submit the form. This will call the script where you do your work in the background, and the user will still be redirected to the payment provider.
Edit: I should mention the snippet here is using jQuery
$("#myForm").submit(function(e) {
// Do your ajax stuff here
});