0

Either I am incredibly stupid or something is wrong with my dev environment. Ive been pulling my hair out of my head for these past few days as my form $_POST variables are simply not getting passed.

So I have scalled it down to the most simplest of tests, just to ensure there is nothing wrong with my script, which I originally thought, which took up all my time trying to find a bug which isnt there. I tried the following and then realise it is a case where $_POST values arent getting passed

<form method="POST" name="login" action="test.php" id="loginForm">
    <input type="text" name="email" placeholder="please enter email">
    <input type="text" name="password" placeholder="please enter your password">
    <button type="submit" name="submitBtn">SUBMIT</button>
</form>

test.php

var_dump($_POST);
$_POST['email'];
$_POST['password'];

I am hoping to get some possible solutions or advise on what I can try to further debug this.

I am using XAMPP, and PHPStorm.

var_dump($_POST) results in NULL{}

Marilee
  • 1,598
  • 4
  • 22
  • 52
  • "email" is not a valid type attribute according to Mozilla. type is not the name, email would be type=text - https://developer.mozilla.org/en-US/docs/Web/HTML/Element/input – Dave S Mar 11 '18 at 04:54
  • Hi just changed it to text now, as I have tried it with text, same result – Marilee Mar 11 '18 at 04:55
  • How are you accessing this in your browser? URL (such as `http://localhost/test.php`) or file (such as `/home/folder/test.php`)? – random_user_name Mar 11 '18 at 04:55
  • `http://localhost/FOLDER/test.php` – Marilee Mar 11 '18 at 04:56
  • Sounds like something could be wrong with your dev environment, possibly PHP config issues. What if you switch to `method="GET"` and `var_dump($_GET)`? – random_user_name Mar 11 '18 at 04:57
  • What page is the form on? If it is also test.php then please post the actual code. – Dave S Mar 11 '18 at 04:57
  • @cale_b gimmie a second to check – Marilee Mar 11 '18 at 04:57
  • @DaveS both under root directory form is `index.php` – Marilee Mar 11 '18 at 04:58
  • @cale_b interestingly. `$_GET` passes values – Marilee Mar 11 '18 at 05:00
  • i don't know how you environment is set up but i came across something like this today, what happens if you try `https://localhost/FOLDER/test.php` , just making sure you're not working with `ssl` – Taki Mar 11 '18 at 05:02
  • Do you have another form in your page ? make sure they don't overlap. – NMC Mar 11 '18 at 05:02
  • So, I'm guessing there's some PHP config issue that is interfering with $_POST. There's lots of posts on this - google "PHP $_POST not working", and one that looks like a good resource is this one: https://stackoverflow.com/questions/9914979/php-post-not-working – random_user_name Mar 11 '18 at 05:02
  • @cale_b Yeah just the frustrating thing is I did NOT change anything and everything worked fine. I dumped it completely down and started a new project under a new root folder. There are only the index.php with post form, and the test.php which is posted aswell. UGH – Marilee Mar 11 '18 at 05:06
  • Your test.php, does it have `` tags? Add just a `echo "test";` to see if your PHP is configured ok to be interpreted. – Nic3500 Mar 11 '18 at 08:05

0 Answers0