Jim R Posted June 1, 2019 Share Posted June 1, 2019 Per usual, I'm having an issue wrapping my head an issue, or I'm just not able to narrow the search well enough. I have a form... method = post action = /process.php Upon hitting process.php, it will UPDATE a data table with the $_POST data it gets from the form. After that, I want to send it to PayPal. It seems like at some point I was able to complete two 'actions' at once, but it's so long since I've created my own forms. Then again, maybe it was a redirect after executing the UPDATE. I just don't remember, and anything I search for doesn't seem to produce results of something that worked. Quote Link to comment https://forums.phpfreaks.com/topic/308781-processing-a-form-and-redirecting/ Share on other sites More sharing options...
ginerjm Posted June 1, 2019 Share Posted June 1, 2019 What "it" do you want to send to paypal? Your form provides the input values; a query statement will save that data to the table. Then what? Send that very same data to paypal in some pre-defined format that Paypal has provided for you? So - follow that format, create the proper string/array/??? that the paypal API has instructed you to do, and deliver it the way the API tells you to do. 1 Quote Link to comment https://forums.phpfreaks.com/topic/308781-processing-a-form-and-redirecting/#findComment-1567225 Share on other sites More sharing options...
requinix Posted June 1, 2019 Share Posted June 1, 2019 If you need to send the user to PayPal then you can't do it from PHP - it's something that needs to happen in the user's browser. The most obvious method would be to have your page show a sort of "processing" message, with the PayPal <form> that automatically (via Javascript) submits itself. If you need to POST data to PayPal but the user doesn't matter then cURL is the answer: you do the work in your code. 1 Quote Link to comment https://forums.phpfreaks.com/topic/308781-processing-a-form-and-redirecting/#findComment-1567226 Share on other sites More sharing options...
Jim R Posted June 1, 2019 Author Share Posted June 1, 2019 I apologize. I do not need to send any data to PayPal. @requinix I figured it wouldn't be done via PHP. If I sent to process.php and had a redirect once there, would it process the UPDATE before redirecting? (All of this because I have to dynamically create values in a dropbox, but that part I have figured out...just not the way to send the User to PayPal afterward as well.) Quote Link to comment https://forums.phpfreaks.com/topic/308781-processing-a-form-and-redirecting/#findComment-1567228 Share on other sites More sharing options...
requinix Posted June 1, 2019 Share Posted June 1, 2019 34 minutes ago, Jim R said: I apologize. I do not need to send any data to PayPal. So... nevermind? No problems? Quote @requinix I figured it wouldn't be done via PHP. If I sent to process.php and had a redirect once there, would it process the UPDATE before redirecting? If that's what you tell your code to do then that's what your code will do. Quote Link to comment https://forums.phpfreaks.com/topic/308781-processing-a-form-and-redirecting/#findComment-1567230 Share on other sites More sharing options...
Jim R Posted June 2, 2019 Author Share Posted June 2, 2019 27 minutes ago, requinix said: If that's what you tell your code to do then that's what your code will do. Don't redirects happen in the header? Quote Link to comment https://forums.phpfreaks.com/topic/308781-processing-a-form-and-redirecting/#findComment-1567234 Share on other sites More sharing options...
ginerjm Posted June 2, 2019 Share Posted June 2, 2019 I am not sure what you are thinking as a "redirect". Most of us may think that you are simply issuing a header("Location: $url)" command to take you to somewhere after having accomplished whatever you wanted to do before going to another script. 1 Quote Link to comment https://forums.phpfreaks.com/topic/308781-processing-a-form-and-redirecting/#findComment-1567238 Share on other sites More sharing options...
Jim R Posted June 2, 2019 Author Share Posted June 2, 2019 I guess it's thinking too linear, that it would redirect before executing the UPDATE. Quote Link to comment https://forums.phpfreaks.com/topic/308781-processing-a-form-and-redirecting/#findComment-1567239 Share on other sites More sharing options...
Jim R Posted June 2, 2019 Author Share Posted June 2, 2019 I got it to work. Thank you! Quote Link to comment https://forums.phpfreaks.com/topic/308781-processing-a-form-and-redirecting/#findComment-1567242 Share on other sites More sharing options...
gizmola Posted June 2, 2019 Share Posted June 2, 2019 3 hours ago, Jim R said: I guess it's thinking too linear, that it would redirect before executing the UPDATE. The Chrome/Firefox dev tools are a great way to explore your understanding of these things. Basically HTTP has a request/response format. Client Makes Request to server ----> Server receives Request (GET or POST) Server processes request.... At this point your PHP code is running and can do whatever you want it to do. So if your goal is to redirect the user to a different page, then you have 2 ways to do that. Either set a location header or use the html meta refresh. In the case of the location header, once anything was echo'd to the client, the http header will have already been sent and it will be too late. Like session_start(), if you need to make header() calls, they have to come first. Of course that doesn't mean that you can't have done processing, stored data, sent email or anything else you require first. 1 Quote Link to comment https://forums.phpfreaks.com/topic/308781-processing-a-form-and-redirecting/#findComment-1567250 Share on other sites More sharing options...
Recommended Posts
Join the conversation
You can post now and register later. If you have an account, sign in now to post with your account.