giggity Posted April 11, 2013 Share Posted April 11, 2013 Before I start I am new to this so if i have left anything out please do tell . I am creating a quiz which is multiple answer. I am using Submit buttons. I have tried multiple codes such as $_GET and $_Post. I am trying to link the buttons so if the user selects the correct answer it outputs a message. I am aware of If statements but get errors . My Attempt so far: <html> <head> <title>A BASIC HTML FORM</title> <?PHP echo '<input type="Radio" name = "4"/>'; echo '<input type="Radio" name = "2"/>'; $correct=4; $correct=$_POST['4']; if($correct == "4" ){ echo "Correct Awnser"; } else { echo "Wrong Awnser"; } ?> PS: I am also using http://phpfiddle.org/ to run my code. Many Thanks Quote Link to comment Share on other sites More sharing options...
lemmin Posted April 11, 2013 Share Posted April 11, 2013 Here is a basic setup of what I think you're trying to do: <html> <head> <title>A BASIC HTML FORM</title> <form> <input type="radio" name="question1" value="1"/> Answer 1<br/> <input type="radio" name="question1" value="2"/> Answer 2<br/> <input type="radio" name="question1" value="3"/> Answer 3<br/> <input type="radio" name="question1" value="4"/> Answer 4<br/> <input type="submit"/> </form> <?php if (isset($_GET['question1'])) //Form was submitted { $correct_answer = 4; $user_answer = $_GET['question1']; if ($user_answer == $correct_answer) echo 'Correct Answer'; else echo 'Wrong Answer'; } ?> Quote Link to comment Share on other sites More sharing options...
giggity Posted April 12, 2013 Author Share Posted April 12, 2013 Thanks a million , thats what I needed Quote Link to comment 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.