-2

When I test php post method, I face some problem. The server will always return 404 error. I don't know if it is the problem of my configuration. But when I turn it onto get method, I can get all the parameters I want.

My environment is : phpstorm+xampp

    <html>
<body>

<form method="post">
    Name: <input type="text" name="name"><br>
    E-mail: <input type="text" name="email"><br>
    <input type="submit">
    Welcome <?php echo $_POST["name"]; ?><br>
    Your email address is: <?php echo $_POST["email"]; ?>
</form>

</body>
</html>
Xin Tu
  • 179
  • 2
  • 12
  • possible duplicate of [PHP code is not being executed I can see it on source code of page](http://stackoverflow.com/questions/5121495/php-code-is-not-being-executed-i-can-see-it-on-source-code-of-page) – Funk Forty Niner May 17 '16 at 00:00

2 Answers2

0

Sounds like you are accessing the file file directly in the browser and not through a HTTP server.

What's the url?

If it's something like file://path/to/file.php this will not work, it needs to be http://localhost/path/to/file.php

James Lockhart
  • 1,030
  • 11
  • 17
0

You may want so specify the action and check if $POST isset, something like:

<form method="post" action="<?php echo htmlentities($_SERVER['PHP_SELF']);?>" >
    Name: <input type="text" name="name"><br>
    E-mail: <input type="text" name="email"><br>
    <input type="submit">
    <br>
<?php
    if(isset($_POST["name"]) and isset($_POST["email"]))
    {
        echo "Welcome". $_POST["name"] . "<br>";
        echo "Your email address is: " .  $_POST["email"];
    }
?>
</form>

Note:

Make sure you run the above code on a server with php installed and running properly.

Pedro Lobito
  • 94,083
  • 31
  • 258
  • 268