I need to create a pretty extensive form with PHP/MySQL with a lot of conditional logic that ultimately ends with submission to the MySQL database. So basically the user makes their first choice with a radio button (has to be because they are "choosing" pictures) and then gets taken to the next "page" of the form based on that submission. That submission ALSO has to be stored in a session or cookie because at the end of the form I will gather all of their input and populate a row in the database. What should my approach be? Right now I'm writing forms that store the POST data in a SESSION and then populate the database row at the end, but as soon as I introduce conditional logic from page to page, the sessions break and don't get sent. Any help would be greatly appreciated.
I did exactly this with a 250 question psychological test system. Once you think it through, it's not too difficult. The solution I used was to output in stacked divs rather than worrying about doing individual pages and posting to session--it's cleaner. A submit button lives on every div, but it only submits on the last one--a function showsthe next div and hides the current div upon click in every other "page". Using variables and PHP math, I can set the test to come out in different combinations--such as 1 page of 250, 5 pages of 50, etc. Your most difficult logic goes into building the page with the proper number of questions and making sure the divs are effectively titled to work with your show/hide script. In my case, I use Jquery's show/hide functionality. Works like a charm.
Because this solution uses one page, you don't have to worry about values being "forgotten" when they go back or forth. In my case, I don't even allow the user to go back because I don't give them any UI to do so. A back click on the browser would give them a warning that they'll be leaving the page. However, you could use several different methods to allow them to go back including UI such as a button, or setting up the back functionality using the browser's back button. A huge side benefit is that loading is next to nothing, and page changes are instantaneous to the user.
Sounds like a classic "wizard" interface. A quick google search brought up this, but I'm not sure if it's any good.
The advantage of saving all data to a single update at the end of the wizard is simplicity. The advantage of writing to the DB after each step is that the user can come back and finish the wizard at a later date - you're not tied to the current user session.
If you're inclined to go with the "insert at the end" approach I'd recommend bpeterson76's idea of using JS to show / hide sections on a singler phisical form - just make sure you've got control of the user's back button, otherwise the user could loose all of their answers.