Caliente Posted December 27, 2011 Share Posted December 27, 2011 I'm new to PHP and attempting to set up my first interactive site that is a basic survey for little kids to take. There's a picture shown to them and two submit buttons below the pic, one reads YES and the other NO to register whether they've participated in the activity before or not. Since the only thing that changes on the page after the selection is made is the photo for the next question/activity, I'd like to be able to use the two buttons to both send their choice to a database (Yes=1 and No=2) and also increment a counter so I can update the picture on the page as they progress through the survey. All the information I've searched/read so far on submit buttons and multiple page surveys doesn't use the actual button itself as data but it's used to submit information gathered elsewhere on the page to another php page for processing via the Action attribute, so I'm wondering if what I want can be done. I'm leaving the Action attribute blank for each button as I want to stay on the same page and attempting to use an incremental counter to update the picture on the page in order to "step" through the survey each time one of the two buttons is clicked, but not having any luck and would appreciate suggestions or points in the right direction on the best way to do this. Apologies in advance if this seems like a basic question, and thanks for any suggestions you can offer. Quote Link to comment https://forums.phpfreaks.com/topic/253880-using-submit-buttons-to-increment-through-content/ Share on other sites More sharing options...
Ivan Ivković Posted December 27, 2011 Share Posted December 27, 2011 As for the counters, you can use cookies. As for the buttons, you can use links with get variable. <a href='survey.php?survey_id=45&page=47&answer=yes'>Yes</a><a href='survey.php?survey_id=45&page=47&answer=no'>Yes</a> And when the user visits, in other words-clicks yes, <a href='survey.php?survey_id=45&page=47&answer=yes'> $_GET['answer'] gets processed, then the website refreshes to next survey survey.php?survey_id=45&page=48 In the database, it's better standard to use smallint(2) and put 0 as NO and 1 as YES. And btw, your username is inappropriate. Quote Link to comment https://forums.phpfreaks.com/topic/253880-using-submit-buttons-to-increment-through-content/#findComment-1301554 Share on other sites More sharing options...
Caliente Posted December 27, 2011 Author Share Posted December 27, 2011 Thanks for the reply. I'm helping a friend who needs to do this survey for her thesis, and she told me for her analysis she needed to use Yes as 1 and No as 2, so that's how I had to assign them. I set up the page trying to use an iterative loop and tried both an IF and FOR statement, but my results were that either all 12 questions and pictures were shown at once, or only one was (which is correct) but I couldn't get the Yes or No button to step through to the next question. I'm not very familiar with cookies at this point and am wondering if there's a way to use a loop to keep it simple? And my user name is just the name of our sailboat, it's all I could think of at such a late hour, and after many failed attempts to get the loop working. I meant no offense by it and will change it if you can tell me how. Quote Link to comment https://forums.phpfreaks.com/topic/253880-using-submit-buttons-to-increment-through-content/#findComment-1301630 Share on other sites More sharing options...
Pikachu2000 Posted December 27, 2011 Share Posted December 27, 2011 Her analysis is odd. OFF/ON are binary states, corresponding to binary numbers 0/1. And Ivan Ivković, just what is it about the OP's username that you find inappropriate? Quote Link to comment https://forums.phpfreaks.com/topic/253880-using-submit-buttons-to-increment-through-content/#findComment-1301634 Share on other sites More sharing options...
Caliente Posted December 27, 2011 Author Share Posted December 27, 2011 Yeah, I'm not sure why she needs it that way, but figured I could pretty much write any value to the database if I can get the loop working? I know the defaults would be easier for sure. Quote Link to comment https://forums.phpfreaks.com/topic/253880-using-submit-buttons-to-increment-through-content/#findComment-1301637 Share on other sites More sharing options...
Caliente Posted December 28, 2011 Author Share Posted December 28, 2011 I've spent another few hours trying to get the iterative loop to work with no success, so since the survey is sequential, guess I'll have to resort to creating individual pages with just the picture being different. Then I can set the Action attribute for each submit button to post to the next page in the series, which will both write that result to the database and set up the next picture. There are over 70 pictures in all, so I was hoping not to have to do it the long way. Quote Link to comment https://forums.phpfreaks.com/topic/253880-using-submit-buttons-to-increment-through-content/#findComment-1301717 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.