[英]if($_SERVER['REQUEST_METHOD'] == 'POST') don't work
I can't explain it, because I'm studying the book learning PHP and I went to test this example and it doesn't work at all.我无法解释它,因为我正在研究学习PHP的书,我去测试这个例子,它根本不起作用。
<?php
if($_SERVER['REQUEST_METHOD'] == 'POST') {
print "hello, ". $_POST['my_name'];
}
else {
print<<<_HTML_
<form method="post" action="$_SERVER[PHP_SELF]">
Your name: <input type="text" name="my name">
<br>
<input type="submit" value="Say Hello">
</form>
_HTML_;
}
?>
As said in the comments your HEREDOC (the <<<HTML
and HTML;
parts) is incorrectly formed.正如评论中所说,您的 HEREDOC(
<<<HTML
和HTML;
部分)的格式不正确。 Below is the corrected one so you can see the difference.以下是更正后的,因此您可以看到差异。
<?php
if ($_SERVER['REQUEST_METHOD'] == 'POST') {
print "hello, " . $_POST['my_name'];
} else {
print<<<HTML
<form method="post" action="$_SERVER[PHP_SELF]">
Your name: <input type="text" name="my name">
<br>
<input type="submit" value="Say Hello">
</form>
HTML;
}
Below is a screen for a working example on replit.com as the OP is using.以下是 OP 正在使用的 replit.com 上的工作示例屏幕。
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.