LoginSignup
0
0

More than 1 year has passed since last update.

PHP selectタグで変数格納

Posted at
select.php
<?php

$selected_value = '';

if ($_SERVER['REQUEST_METHOD'] === 'POST') {
    if (isset($_POST['my_select'])) {
        $selected_value = $_POST['my_select'];
        echo "選択された値: " . $selected_value;
    } else {
        echo "値が選択されていません。";
    }
}

$html = <<<EOT
<!DOCTYPE html>
<html>
<head>
    <title>PHP Select Example</title>
</head>
<body>
    <form action="{$_SERVER['PHP_SELF']}" method="post">
        <select name="my_select">
            <option value="option1">オプション1</option>
            <option value="option2">オプション2</option>
            <option value="option3">オプション3</option>
        </select>
        <input type="submit" value="送信">
    </form>
</body>
</html>
EOT;

echo $html;
?>
0
0
0

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
0
0