PHPで簡易的なサイトを作っています。
別のPHPファイルに変数の受け渡しができません。
実現したいこと
index.phpファイル上で名前を入力してもらい、question.phpファイルで入力データを取得し
answer.phpファイルでも入力データを取得し表示させたいです。
発生している問題・エラーメッセージ
エラーこそ出ていないもののincludeなど試してみましたが、ファイルの受け渡しが全文受け渡され
変数データだけの受け渡しができません。
該当のソースコード
index.php <!DOCTYPE html> <html lang="ja"> <head> <meta charset="UTF-8"> <meta http-equiv="X-UA-Compatible" content="IE=edge"> <meta name="viewport" content="width=device-width, initial-scale=1"> <title></title> <link rel="stylesheet" href="style.css"> </head> <body> <div class="header"> <h1>2章チェックテスト</h1> </div> <div class="main"> <form action="question.php" method="post" class="form_tag"> <input type="text" placeholder="名前を入力してください" name="my_name"> <input type="submit" value="テスト開始" name="submit" class="submit"> </form> </div> </body> </html> question.php <?php $name = $_POST["my_name"]; ?> <!DOCTYPE html> <html lang="ja"> <head> <meta charset="UTF-8"> <meta http-equiv="X-UA-Compatible" content="IE=edge"> <meta name="viewport" content="width=device-width, initial-scale=1"> <title></title> <link rel="stylesheet" href="question.css"> </head> <body> <div class="main"> <p>お疲れ様です<?php echo $name; ?>さん</p> <form action="answer.php" method="post"> <h2>①ネットワークのポート番号は何番?</h2> <?php $number = [80,22,20,21]; foreach ($number as $value) { ?> <input type="radio" name="port_number"> <?php echo $value; } ?> <h2>②Webページを作成するための言語は?</h2> <?php $langage = [PHP,Python,JAVA,HTML]; foreach ($langage as $value) { ?> <input type="radio" name="langages"> <?php echo $value; } ?> <h2>③MySQLで情報を取得するためのコマンドは?</h2> <?php $comand = [join,select,insert,update]; foreach ($comand as $value) { ?> <input type="radio" name="comand_type"> <?php echo $value; } ?> <br> <input type="submit" value="回答する"> </form> </div> </body> </html> answer.php <?php $name = $_POST["my_name"]; echo $name; ?>