Skip to content

Instantly share code, notes, and snippets.

@makzan
Created September 8, 2017 02:46
Show Gist options
  • Save makzan/440371d1fae91f1648a5b77eda0b4a0e to your computer and use it in GitHub Desktop.
Save makzan/440371d1fae91f1648a5b77eda0b4a0e to your computer and use it in GitHub Desktop.
Sample PHP code
<?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