我想提交一个表单,提交后,网页不会进入不同的页面。以下是我查看的一些资源:php form - on sumbit stay on same page和php and html form on the same page。然而,他们的解决方案似乎都没有完全奏效,也就是说,它帮助我弄清楚如何将PHP代码放在与HTML相同的文件中,而不是在网站上“回显”任何消息我不确定PHP是否真的有效。所以这里是我的代码:住在同一页PHP和HTML
<!DOCTYPE html>
<html>
<body>
<form method="post" enctype="multipart/form-data">
Select image to upload:
<input type="file" name="fileToUpload" id="fileToUpload">
<input type="submit" value="Upload Image" name="submit">
</form>
<?php
if(isset($_POST['submit']))
{
echo "yo! what up homie?!";
}
else
{
// Display the Form and the Submit Button
}
?>
</body>
</html>
上传文件并提交后,网页不会转到不同的页面。但是,它并没有回应yo! what up homie?!
。有关如何留在同一页面并在用户按下提交按钮后回显消息的任何建议?
任你想要形式,还是那个信息? –
我希望消息在表单提交时显示。所以我知道'if(isset($ _ POST ['submit'])){}'中的代码正在执行。 –
其工作正常。 –