Reputation: 11
I am trying to get the user input and verify if the answer is correct using an if and statement. How do I prompt the user for input within the same webpage? This is the code I have so far.
<?php
$answer = //user input
if ($answer = "4") {
echo " “Correct!!!! Congratulations!";
} else {
echo "Your answer was blank but the correct answer is 4.";
}
?>
Upvotes: 0
Views: 3914
Reputation: 516
This is the full form view to let you know how to perform the basic form submit and get values and displaying the result
<?php
if(isset($_POST['submit']))
{
$answer=$_POST['answer'];
if ($answer == "4") {
echo " “Correct!!!! Congratulations!";
} else {
echo "Your answer was blank or wrong input but the correct answer is 4.";
}
}
?>
<html>
<body>
<form method="post" action="index.php">
<input type="number" name="answer">
<input type="submit" name="submit" value="Submit">
</form>
Upvotes: 1