Basically what I am trying to do is, make is to that if and only if someone goes through with the payment and pays it will write certain data to an SQL server. I understand i could just redirect them to a page that runs the code but the issue is they could just refresh infinitely. Any ideas?
Check your Paypal documentation, but when I did this last, the interface had a place where you can put your receiving URL. There you can test for $_POST["RESPMSG"] == "Approved"