LoginSignup
2
1

More than 5 years have passed since last update.

PHPでフォームから値を受け取り、$_GETで新しい別のページに値を受け渡して表示する

Last updated at Posted at 2018-08-13

htmlのformに入れた値を、次に遷移するページへ受け渡す方法です。
実際にソースを書く時には、「空欄の時はリンク先へ飛ばない」、「テキストしか受け付けない」などの記述を追加する必要があります。

送信する側

<html>
 <head>
  <title>タイトル</title>
 </head>
 <body>
    <h1>入力画面</h1>
    <form action = "result.php" method = "get">
        <input type = "text" name = "result" placeholder = "keywords"></br>
        <input type = "submit" value = "Go">
    </form>
</body>
</html>

受信する側

<html>
 <head>
  <title>受け渡し結果</title>
 </head>
 <body>
    <h1>受け渡し結果</h1>
    <p>
        <?php
            $result = $_GET["result"];
            echo htmlspecialchars($result, ENT_QUOTES, 'UTF-8'); //文字列に変換
        ?>
    </p>
</body>
</html>
2
1
3

Register as a new user and use Qiita more conveniently

  1. You get articles that match your needs
  2. You can efficiently read back useful information
  3. You can use dark theme
What you can do with signing up
2
1