indexのコピー.php
<?php
$title1 = '動物の種類は何でしょうか?';
$title2 = '何才でしょうか?';
$title3 = '好きな触られ方は何でしょうか?';
$quistion1 = array('猫', '犬', '狛犬', '人間');
$quistion2 = array('11才', '10才', '12才', '15才');
$quistion3 = array('なでなで', 'スリスリ', 'もふもふ', 'ツンツン');
$answer1 = $quistion1[0];
$answer2 = $quistion2[0];
$answer3 = $quistion3[0];
shuffle($quistion1);
shuffle($quistion2);
shuffle($quistion3);
?>
<!DOCTYPE html>
<html lang="en">
<head>
<meta charset="UTF-8">
<meta name="viewport" content="width=device-width, initial-scale=1.0">
<meta http-equiv="X-UA-Compatible" content="ie=edge">
<title>クイズ</title>
</head>
<body>
<h1>○○○○さんについての質問</h1>
<h2><?php echo $title1; ?></h2>
<form method="post" action="answerのコピー.php">
<?php foreach($quistion1 as $value) { ?>
<input type="radio" name="question1" value=" <?php echo $value; ?> "> <?php echo $value; ?><br>
<div><?php echo $value; ?></div>
<?php } ?>
<input type="hidden" name="answer1" value=" <?php echo $answer1; ?> ">
<div><?php echo $answer1; ?></div>
<h2><?php echo $title2; ?></h2>
<?php foreach($quistion2 as $value) { ?>
<input type="radio" name="question2" value=" <?php echo $value; ?> "> <?php echo $value; ?><br>
<div><?php echo $value; ?></div>
<?php } ?>
<input type="hidden" name="answer2" value=" <?php echo $answer2; ?> ">
<div><?php echo $answer2; ?></div>
<h2><?php echo $title3; ?></h2>
<?php foreach($quistion3 as $value) { ?>
<input type="radio" name="question3" value=" <?php echo $value; ?> "> <?php echo $value; ?><br>
<div><?php echo $value; ?></div>
<?php } ?>
<input type="hidden" name="answer3" value=" <?php echo $answer3; ?> ">
<div><?php echo $answer3; ?></div>
<input type="submit" name="submit">
</form>
</body>
</html>
answerのコピー.php
<?php
$question1 = $_POST['question1'];
$answer1 = $_POST['answer1'];
$question2 = $_POST['question2'];
$answer2 = $_POST['answer2'];
$question3 = $_POST['question3'];
$answer3 = $_POST['answer3'];
// 結果の判定
if ($question1 == $answer1) {
$result1 = "正解!";
}else{
$result1 = "不正解";
}
if ($question2 == $answer2) {
$result2 = "正解!";
}else{
$result2 = "不正解";
}
if ($question3 == $answer3) {
$result3 = "正解!";
}else{
$result3 = "不正解";
}
?>
<!DOCTYPE html>
<html lang="en">
<head>
<meta charset="UTF-8">
<meta name="viewport" content="width=device-width, initial-scale=1.0">
<meta http-equiv="X-UA-Compatible" content="ie=edge">
<title>Document</title>
</head>
<body>
<h2>クイズの結果 1問目</h2>
<?php echo $result1; ?>
<h2>クイズの結果 2問目</h2>
<?php echo $result2; ?>
<h2>クイズの結果 3問目</h2>
<?php echo $result3; ?>
</body>
</html>