Created
September 8, 2017 02:46
-
-
Save makzan/440371d1fae91f1648a5b77eda0b4a0e to your computer and use it in GitHub Desktop.
Sample PHP code
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
<?php | |
$is_correct = false; | |
$answer = ""; | |
if (isset($_POST['answer'])) { | |
$answer = $_POST['answer']; | |
if ($answer == 150) { | |
$is_correct = true; | |
} | |
} | |
?> | |
<!DOCTYPE html> | |
<title>問答題</title> | |
<h1>100 + 100 / 2 = ?</h1> | |
<?php if ($answer==""): ?> | |
<form action="" method="POST"> | |
<input type="text" name="answer" autofocus> | |
<input type="submit"> | |
</form> | |
<?php else: ?> | |
<p><?= $answer ?></p> | |
<?php if ($is_correct): ?> | |
<p><strong>Correct!</strong></p> | |
<?php else: ?> | |
<p><strong>Incorrect. Let's make another try.</strong></p> | |
<form action="" method="POST"> | |
<input type="text" name="answer" value="<?= $answer ?>" autofocus> | |
<input type="submit"> | |
</form> | |
<?php endif; ?> | |
<?php endif; ?> | |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment