-1

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> 
Yoni Tareke
  • 11
  • 1
  • 2

2 Answers2

2

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>
Community
  • 1
  • 1
Ferrakkem Bhuiyan
  • 2,741
  • 2
  • 22
  • 38
  • I did `not` downvote, but I can tell by your [original answer](http://stackoverflow.com/revisions/25894145/1) that you had not changed the `“ ”` and `‘ ’` in OP's code. Most probable reason and that person has not retracted it. – Funk Forty Niner Sep 17 '14 at 15:15
  • 1
    But Sir @Fred i am give the full answer ..with solve the error .. is it sir – Ferrakkem Bhuiyan Sep 17 '14 at 15:17
  • 1
    It was me. @Fred-ii- was right, when the original answer was published, it has illegal quotes still present, so I've downvoted it. Now I've pulled my vote back. – YuS Sep 17 '14 at 15:27
  • 1
    @FerrakkemBhuiyan I made a few modifications/clarifications to your answer in order to point out to the OP, where the errors were made. It's always best to do that and to give a detailed answer. ;) – Funk Forty Niner Sep 17 '14 at 15:53
  • @FerrakkemBhuiyan You're welcome. Sorry, I do not give out my Email publicly. See my Website ;) – Funk Forty Niner Sep 17 '14 at 15:56
  • @FerrakkemBhuiyan Why do you want me to have your Email address? – Funk Forty Niner Sep 17 '14 at 16:00
  • @Fred-ii- your are more senior and i see your profile too really awesome .i need some guide-line from you if you don't have any problem and this is my ferrakkem@gmail.com ... thank you sir – Ferrakkem Bhuiyan Sep 17 '14 at 16:02
0

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>
Funk Forty Niner
  • 74,450
  • 15
  • 68
  • 141
YuS
  • 2,025
  • 1
  • 15
  • 24
  • This `enctype="text/plain"` should be removed. See http://stackoverflow.com/a/7628491/ for more information about that. – Funk Forty Niner Sep 17 '14 at 15:32
  • Using `enctype="text/plain"` will fail, just thought you would like to know that. – Funk Forty Niner Sep 17 '14 at 15:54
  • I did not refactor the original code (except `body` tag). Just managed the quotes and format. And also you are almost right (atleast for that `welcome.php`). However, even if you submit the form with `enctype="text/plain"` you can still catch the data in PHP with `file_get_contents('php://input')`. – YuS Sep 18 '14 at 08:40