0

I am having some problems with the POST method for form submission in a localhost. I created a very simple page to test if both GET and POST methods work, but only the GET method is retrieving correctly the values. The code is as follows:

The form code:

<form method="post" action="login.php">
    <input type="text" name="username"><br>
    <input type="password" name="password"><br>
    <input type="submit" value="Login">
</form>

In the login.php page, I issue just a simple command to test if there is any value in the $_POST variable:

<?php var_dump($_POST);?>

which turns out to be an empty array.

However, if I change the method to GET, the command

<?php var_dump($_GET);?>

prints the following result:

array (size=2)
  'username' => string 'test' (length=4)
  'password' => string 'test' (length=4)

I have searched a lot of threads, but most of them were pointing coding errors, which does not seem to be the case here. In any case, if this information is useful, I am using WampServer 2.5 and PhpStorm 10.

Thanks a lot for your help!

Best, Lauro

2 Answers2

0

There is nothing wrong with the code you have posted. You can check your login.php with a HTTP client(e.g. Postman) whether it is catching the post values or not. Moreover, for a test purpose try submitting the form in the same page. Then var_dump the $_POST variable. Besides you also should check $_REQUEST variable whether it is containing the value or not.

Imran
  • 4,582
  • 2
  • 18
  • 37
0

My guess is that this a PHPStorm 10 issue (see here). They'll probably fix it soon.

You can work around it by using file_get_contents('php://input');, or by reverting back to an earlier version of PHPStorm.

You might also be able set up a virtual machine with something like Vagrant and configure PHPStorm to use that. Looks like PHPStorm has an integration with Vagrant already.

Steve Perry
  • 556
  • 4
  • 11