我只是 PHP 和 Html 的初学者。我已经看到了很多与此相关的 SO 问题,但不知何故无法在我的最后解决一个非常简单的问题。所以,请帮忙。
以下代码似乎不起作用。当我运行此代码时,表单前总是有一条消息“现在似乎有问题。请稍后再试”。无论我是否按下提交按钮,都没有任何区别。
<h2 >Inquiry form</h2>
<?php
if (isset($_POST['submit'])){
echo "Thank You!";
}
else {
echo "There seems to be a problem right now. Please try again after sometime";
}
?>
<form name="input" method="POST" action="contact.php">
<label for="Name">Name (required):</label>
<br />
<input type="text" name="Name" />
<br />
<div class="clear"></div>
<label for="inputmail">Email(required):</label>
<br />
<input type="text" name="email" />
<br />
<div class="clear"></div>
<label for="inputtelefon">Phone:</label>
<br />
<input type="text" name="phone" />
<br />
<div class="clear"></div>
<label for="inputmessage">Message:</label>
<br/>
<textarea name="message" cols="28" rows="3" ></textarea>
<div class="clear"></div>
<div id="send">
<input type="submit" value=" Submit " />
<input type="reset" value=" Clear " />
</div>
</form>
更改代码:
<h2 >Inquiry form</h2>
<?php
if ($_SERVER['REQUEST_METHOD'] == 'POST') {
//if ($_SERVER['REQUEST_METHOD'] == 'POST') { This is not working as well
echo "Thank You!";
}
else {
echo "There seem to be a problem right now. Please try again after sometime";
}
?>
<form name="input" method="POST" action="contact.php">
<label for="Name">Name (required):</label>
<br />
<input type="text" name="Name" />
<br />
<div class="clear"></div>
<label for="inputmail">Email(required):</label>
<br />
<input type="text" name="email" />
<br />
<div class="clear"></div>
<label for="inputtelefon">Phone:</label>
<br />
<input type="text" name="phone" />
<br />
<div class="clear"></div>
<label for="inputmessage">Message:</label>
<br/>
<textarea name="message" cols="28" rows="3" ></textarea>
<div class="clear"></div>
</div>
<div id="send">
<input type="submit" value=" Submit " name="submit"/>
</div>
</form>