404错误,在mamp服务器上,找不到文件


404 error, on mamp server, file not found

在尝试访问MAMP 上的PHP文件时,我收到以下404错误

"在此服务器上找不到请求的URL/'welcome.php'。"

html文件和php文件都可以通过localhost运行,而不是通过文件操作运行。

它们在同一个位置,操作看起来像action='welcome.php'

  <html><head charset=“utf-8”>></head><form action=‘welcome.php’ enctype="text/plain" method=“post”>      
  First name: <input type="text" name="firstname"><br> Last name: <input type="text"   
  name="lastname"> <button action=“submit”>Submit </button> </form> </html>

welcome.php看起来像这个

  <html> <body> Welcome <?php echo $_POST["name"]; ?><br> Your email address is: <?php echo   
   $_POST["email"]; ?> </body> </html> 

您的代码“ ”‘ ’中有几个花引号,这将解释表单操作action=‘welcome.php’的"找不到文件"错误。您还应该删除enctype="text/plain"-有关它的更多信息,请参阅Stack上的答案

您也使用了错误的名称name="firstname"$_POST["name"]
还有name="lastname"$_POST["email"],它们必须匹配。

您的Html文件现在应该读作:

<html>
<body>
<form action="welcome.php" method="post">
Name: <input type="text" name="name"><br>
E-mail: <input type="text" name="email"><br>
<input type="submit">
</form>
</body>
</html>

和welcome.php文件:

<html>
<body>
Welcome <?php echo $_POST["name"]; ?><br>
Your email address is: <?php echo $_POST["email"]; ?>
</body>
</html>

在此服务器上找不到请求的URL/'welcome.php'

这是因为您在HTML中使用了错误的引号。在标记中,除了"'之外,不应使用其他任何内容。

所以你的代码应该看起来像:

<html>
<head charset="utf-8"></head>
<body>
  <form action="welcome.php" enctype="text/plain" method="post">
    First name: <input type="text" name="firstname"><br>
    Last name: <input type="text" name="lastname">
    <button action="submit">Submit</button>
  </form>
</body>
</html>