php/ html/ forms/ http-status-code-404/ mamp

I get the following 404 error when trying to access a PHP file on MAMP

"The requested URL /'welcome.php' was not found on this server."

Both the html file and the php file run fine via localhost just not from the file action.

They are in the same location and the action looks like 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 looks like this

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

   $_POST["email"]; ?> </body> </html> 

You have a few curly quotes in your code “ ” and ' ' which will explain the "file not found" error for your form's action action='welcome.php' . You should also remove enctype="text/plain" - consult this answer on Stack for more information about it.

You are also using the wrong names name="firstname" and $_POST["name"] .
Also name="lastname" and $_POST["email"] , those must match.

Your Html file should now read as:

<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>

and welcome.php file:

<html>
<body>

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

</body>
</html>

The requested URL / 'welcome.php' was not found on this server.

This is because you use wrong quotes (quotation marks) in your HTML. In markup you should use nothing else then " or ' .

So your code should looks like:

<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>

暂无
暂无

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

Related Question MAMP giving 404 error - file not found 404 Error: localhost MAMP server cannot find javascript file MAMP - Phpmyadmin (Error in processing, error code : 404, error not found) 404 file not found error in live server website is based on codeignitter framework Local host setup with MAMP & phpMyAdmin. File not found on this server Live server error but not on MAMP Tinymce 404 error but file is on the server File upload 404 error on server 404 Error on all pages in local site (MAMP) 404 not found error on localhost .php file
 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM