Connecting Tech Pros Worldwide Help | Site Map

Using multiple buttons with PHP

Newbie
 
Join Date: Oct 2009
Posts: 2
#1: Oct 13 '09
I am currently trying to make a four question quiz. Each question is on a new page. There will be a previous button and a next button to take the user to the previous and next question respectively. There will also be a save button to save the current answer selected for the questions so far. Finally, I will have a submit button that will submit all the answers of the quiz and give back a score. I have to use these buttons, and I have to have my page setup in this way. However, I am not sure how I should handle the buttons.

I currently have my HTML file as such which will send to a php file:

Expand|Select|Wrap|Line Numbers
  1. <h1>Music Quiz</h1>
  2.   <form action = "exam1.php" method = "post">
  3.     <p>
  4.       Which of the following composers were NOT famous during the
  5.       Renaissance period (1600-1750)? <br />
  6.       <select name = "questionOne">
  7.         <option></option>
  8.         <option value = "Guillaume Dufay">Guillaume Dufay</option>
  9.         <option value = "Josquin des Prez">Josquin des Prez</option>
  10.         <option value = "Henry Purcell">Henry Purcell</option>
  11.         <option value = "Palestrina">Palestrina</option>
  12.       </select>
  13.     </p>
  14.     <p>
  15.           <input type ="button" value="Previous Question" />
  16.       <input type = "submit" value = "Save" />
  17.           <input type = "submit" value = "Submit" />
  18.           <input type = "button" value = "Next Question" />
  19.     </p>
  20.   </form>
The PHP file can print the next question if the next question button was selected, etc. I should be able to handle everything in the php file. However, I don't know how to determine which buttons were pressed in my php file. How should I handle the next and previous buttons? How do I know which submit button was selected? Any help will be greatly appreciated.
code green's Avatar
Expert
 
Join Date: Mar 2007
Location: England
Posts: 1,076
#2: Oct 13 '09

re: Using multiple buttons with PHP


Give them different names
Newbie
 
Join Date: Oct 2009
Posts: 2
#3: Oct 13 '09

re: Using multiple buttons with PHP


How do you refer to the names in the PHP code? How can I make the PHP handle next and previous? Any ideas?
Dormilich's Avatar
Moderator
 
Join Date: Aug 2008
Location: Leipzig, Germany
Posts: 3,623
#4: Oct 13 '09

re: Using multiple buttons with PHP


Quote:

Originally Posted by brian210 View Post

How do you refer to the names in the PHP code?

Expand|Select|Wrap|Line Numbers
  1. $_POST['name']
Quote:

Originally Posted by brian210 View Post

How can I make the PHP handle next and previous? Any ideas?

save somewhere the sequence of the files and walk through that. (there are too many possibilities to list them all)
Reply

Tags
buttons, database, forms, quiz, submit