Help us understand the problem. What is going on with this article?

PHP 基礎フォーム

More than 3 years have passed since last update.

$_POSTの中身

Array ( [name] => 名前 [renraku] => denwa [Submit] => 確認 )

$_POSTは変数の連想配列

■kisoform.php

<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN"
"http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
<html xm1ns="http://www.w3.org/1999/xhtml">
<html lang="ja">
<head>
<meta http-equiv="Content-Type" content="text/html; charset=UTF-8" />
<meta http-equiv="Content-Script-Type" content="text/javascript">


    <title>在庫確認買取お見積り 問い合わせフォーム</title>

</head>
<body>
    <h1>
        <font color="#ff9933">在庫確認買取お見積り 問い合わせフォーム</font>
    </h1>
    お客様情報を入力して下さい
    <form action="kisoform_confirm.php" method="post" type="submit">
        <p>
            お名前<input type="text" name="name">

        </p>
        <p>
            ご希望の連絡方法 <input type="radio" name="renraku" value="denwa" checked>電話
                <input type="radio" name="renraku" value="mail">メール

        </p>

        <input type="submit" name="Submit" value="確認">

    </form>

</body>
</html>


kisoform_confirm.php

<?php
$name = $_POST ['name'];
$renraku = $_POST ['renraku'];
if ($renraku == "denwa") {
    $renraku = "電話";
} else if ($renraku == "mail") {
    $renraku = "メール";
}
echo "<pre>";
print_r ( $_POST );
print_r ( $name );
print_r ( $renraku );
echo "<pre>";
?>

<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN"
"http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
<html xm1ns="http://www.w3.org/1999/xhtml">
<html lang="ja">
<head>
<meta http-equiv="Content-Type" content="text/html; charset=UTF-8" />
<meta http-equiv="Content-Script-Type" content="text/javascript">


    <title>在庫確認・買取お見積り 問い合わせフォーム</title>

</head>
<body>
    <h1>
        <font color="#ff9933">在庫確認・買取お見積り 問い合わせフォーム</font>
    </h1>
    以下の内容で送信します
    <form action="kisoform_complete.php" method="post">
        <p>お名前:<?php echo $name; ?></p>
        <p>ご希望の連絡方法:<?php echo $renraku; ?></p>
        <input type="submit" name="Submit" value="送信">

    </form>
</body>
</html>


$name = $_POST ['name'];の$_POST ['name'];のnameはkisoform.phpの<input type="text" name="name">の"name"と同じ

■kisoform_complete.php

<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN"
"http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
<html xm1ns="http://www.w3.org/1999/xhtml">
<html lang="ja">
<head>
<meta http-equiv="Content-Type" content="text/html; charset=UTF-8" />
<meta http-equiv="Content-Script-Type" content="text/javascript">


<title>PHP入門</title>
</head>
<body>
    <div>
        <h1>完了</h1>
        送信が完了しました <br> <br> <a href="./kisoform.php">戻る</a>

    </div>
</body>
</html>

■kisoform.php 実行結果
Array
(
[name] => 名前
[renraku] => denwa
[Submit] => 確認
)
名前電話
kisoform入力画面.png

kisoformpost中身.png

参考

icelandnono
24歳です 職場は渋谷です 渋谷興味ない。。 新橋とかで働きたい。。銀座がすき
Why not register and get more from Qiita?
  1. We will deliver articles that match you
    By following users and tags, you can catch up information on technical fields that you are interested in as a whole
  2. you can read useful information later efficiently
    By "stocking" the articles you like, you can search right away