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.