adambedford Posted February 6, 2010 Share Posted February 6, 2010 I'm creating a web application that needs visitors to be able to pay with paypal. I want customers to fill in the form that will store their information in a database and then be transferred to paypal to complete the transaction. I don't want the record in the database to be created until the payment has been authorised (so maybe it could be done when the confirmation page loads when the visitor is returned to my site from paypal?) My queestion is this: How do I store the data they entered in the form temporarily while they complete payment and then write it permanently once confirmation is received? I'm thinking that I could store the data as a session and then write this to the table on the confirmation page. Would that work? If so, how would I go about it? (I'm relatively new to PHP). PS. If anyone knows anything about the PayPal API and payment authentication as well that would be brilliant! Link to comment https://forums.phpfreaks.com/topic/191143-storing-form-data-as-a-php-session/ Share on other sites More sharing options...
Catfish Posted February 6, 2010 Share Posted February 6, 2010 session_start(); $_SESSION['someVariable'] = 'Some data'; ensure session_start() gets called on subsequent pages to access the session data again. Link to comment https://forums.phpfreaks.com/topic/191143-storing-form-data-as-a-php-session/#findComment-1007866 Share on other sites More sharing options...
adambedford Posted February 6, 2010 Author Share Posted February 6, 2010 Thanks! So do I repeat $_SESSION['someVariable'] = 'Some data'; for each form variable I have? Link to comment https://forums.phpfreaks.com/topic/191143-storing-form-data-as-a-php-session/#findComment-1007874 Share on other sites More sharing options...
adambedford Posted February 6, 2010 Author Share Posted February 6, 2010 Also, do you think that Sessions is the best way to go about this? Or is there a better alternative? i.e. Writing to a temporary table or using Cookies etc? Link to comment https://forums.phpfreaks.com/topic/191143-storing-form-data-as-a-php-session/#findComment-1007877 Share on other sites More sharing options...
Catfish Posted February 6, 2010 Share Posted February 6, 2010 there's many ways to skin a cat. sessions i think would be the easiest. if you want the user to be allowed to timeout or lose their session and come back and retrieve the data then look at an alternate storage method like you mentioned. Link to comment https://forums.phpfreaks.com/topic/191143-storing-form-data-as-a-php-session/#findComment-1007878 Share on other sites More sharing options...
adambedford Posted February 6, 2010 Author Share Posted February 6, 2010 So how would I go about storing the data entered in this form as session variables? <form id="form" name="form" method="post" action=""> <div id="websitewrapper"> <label for="Website_name" class="label_left">Website Name</label> <input type="text" name="Website_name" id="Website_name" /> </div> <div id="URLwrapper"> <label for="URL2" class="label_left">URL (Web Address)</label> <input type="text" name="URL" id="URL2" /> </div> <div id="descriptionwrapper"> <label for="Description2" class="label_left">Description</label> <textarea name="Description" cols="35" rows="4" id="Description2"></textarea> </div> <div id="categorywrapper"> <label for="Category_ID2" class="label_left">Category</label> <select name="Category_ID" size="1" id="Category_ID2"> </select> </div> <div id="highlightwrapper"> <label for="Highlighted2" class="label_left">Highlighted</label> <input type="checkbox" name="Highlighted" value="Highlighted" id="Highlighted" /> </div> <div id="featuredwrapper"> <label for="Featured2" class="label_left">Featured</label> <input type="checkbox" name="Featured" value="Featured" id="Featured" /> </div> <div id="homepagewrapper"> <label for="Homepage2" class="label_left">Homepage Featured</label> <input type="checkbox" name="Homepage" value="Homepage" id="Homepage" /> </div> </form> Link to comment https://forums.phpfreaks.com/topic/191143-storing-form-data-as-a-php-session/#findComment-1007979 Share on other sites More sharing options...
Catfish Posted February 6, 2010 Share Posted February 6, 2010 I'm not 100% sure how the values work with checkboxes, but you would do something like this: // $_POST data validation code can go here to make sure data is ok for use. session_start(); // start session foreach($_POST as $keyName => $value) // loop through $_POST array values { $_SESSION[$keyName] = $value; // assign each value of $_POST to a session variable of the same name } Try doing print_r($_POST); and print_r($_SESSION); to look at the data inside the $_POST and $_SESSION arrays to debug and ensure your data is travelling around and being stored correctly. Link to comment https://forums.phpfreaks.com/topic/191143-storing-form-data-as-a-php-session/#findComment-1008114 Share on other sites More sharing options...
jl5501 Posted February 6, 2010 Share Posted February 6, 2010 if you have <input type="hidden" name="rm" value="2"> as a hidden value in your paypal form, then all data will be posted back to your return page and be available as POST Link to comment https://forums.phpfreaks.com/topic/191143-storing-form-data-as-a-php-session/#findComment-1008117 Share on other sites More sharing options...
Recommended Posts
Archived
This topic is now archived and is closed to further replies.