Harry12345 Harry12345 - 2 months ago 4x
PHP Question

PHP - making a switch statement using id from form input

I'm making a short quiz in PHP that tells you what creature your thinking of based on 4 yes/no questions. I have made it so that depending on your answer to each question you get taken to a different question, I did this using mainly switch statements.

My question is is there any way that I can make a switch statement with the condition as the id from the submit buttons from the form?

echo "<form method ='post' action='Creatures.php'>
<input type='submit' name='answer' id='1' value='Yes' />
<input type='submit' name='answer' id='2' value='No' />

This is the form I'm using to display the buttons, I have made it so that each button has a different id so at the end of the quiz, depending on what the id of the last button pressed is, I can display the right answer. Below is what I tried to do but it didn't work.

case 1: echo "It's a goldfish";
case 2: echo "It's a eel";

Also these fields are the only ones which use id's throughout the whole web page, any suggestions on how I can get this to work properly, not necessarily using switch statements?

switch($_POST['answer']) {

case 'Yes':
   // do soemthing
case 'No':
   // do something