Jump to content

Using submit buttons to increment through content


Caliente

Recommended Posts

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.

 

 

 

 

 

 

 

 

Link to comment
Share on other sites

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. :P

Link to comment
Share on other sites

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.

Link to comment
Share on other sites

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.

Link to comment
Share on other sites

This thread is more than a year old. Please don't revive it unless you have something important to add.

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.

Guest
Reply to this topic...

×   Pasted as rich text.   Restore formatting

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

×
×
  • Create New...

Important Information

We have placed cookies on your device to help make this website better. You can adjust your cookie settings, otherwise we'll assume you're okay to continue.