剛開始學php
單純想要測試php post表單並顯示輸入值
<body>
<?php
$User = "";
if ($_SERVER["REQUEST_METHOD"] == "POST")
{
if(isset($_POST["User"])) {
$User = $_POST["User"];
}
}
?>
<form method="post" action="<?php echo htmlspecialchars($_SERVER["PHP_SELF"]);?>">
<input type="text" name="User" />
<input type="button" value="Submit">
</form>
<?php
echo "<h3>input</h3>";
echo $User;
echo "<br>";
?>
</body>
但是按鈕點下去都沒反應,不太清楚是按鈕沒讀取到還是讀取到但是沒動作
環境是用docker蓋的,不知道有沒有關係
version: '3'
services:
nginx:
image: nginx:stable-alpine
ports:
- "8083:80"
volumes:
- ./conf.d:/etc/nginx/conf.d
- ./php:/var/www/html
links:
- myphp-fpm:php
myphp-fpm:
image: php:rc-fpm-alpine3.12
ports:
- "9000:9000"
volumes:
- ./php:/var/www/html
查了一下php:rc-fpm-alpine3.12 應該是用php8.0
<input type="button" value="Submit">
不會 submit
可以用 <button>Submit</button>
或是 <input type="submit" value="Submit">
問題出在這裏
<input type="button" value="Submit">
你宣告這個input元件type為按鍵(button),而不是發送(submit)
改一下宣告就會發送了。
<input type="submit" value="Submit">