0

After reading 20+ posts (a large majority of which involve people failing to put the name attribute in their input tags), I have a stupidly simple script:

<form action="submit_form.php" method="post">
        Name: <input type="text" name="name"><br>
        <input type="submit">
</form>

and on submit_form.php I have

<?php echo $_POST["name"]; ?>

Which spits out the text below.

Notice: Undefined index: name in C:\Users...\PhpstormProjects...\submit_form.php on line 1

I've been using PHP for years though this is the first PHP project on this fresh machine so this is the first post type action I've tried on the new configuration. With that said, I have a feeling it has to do with my PHP configuration? What should I look for inphpinfo()?

As a probably very important note:

  • I'm running this on PhpStorm
  • I've set all the deployment settings (I use PhpStorm at work with no problem)
  • After posting the form from the index page, I've had submit_form.php only execute phpinfo(); and that works except...
  • I get random 502's... Half of the time I see the PHP info, the other half of the time I get 502 Bad Gateway...

I've also tried:

if(isset($_POST["name"])) {
 echo $_POST["name"];
}
8protons
  • 3,591
  • 5
  • 32
  • 67

2 Answers2

0

First try

var_dump($_POST)

Because i think you're posting data to a wrong file. that's why you're not getting anything from var_dump .. please check that submit_form.php filename

if it doesn't work!

How about try something from beginning .

First create a file name: setup.php

<form action="post.php" method="post">
        Name: <input type="text" name="name"><br>
        <input type="submit" name="submit">
</form>

Then Create another file in the same directory called post.php

<?php 

     if(isset($_POST["name"])) {
       $name = $_POST["name"];
     }   

     echo $name;

?>

Hopefully my solution will work for you!

Aniruddha Chakraborty
  • 1,849
  • 1
  • 20
  • 32
0

The following link to a blog might help you resolve your problem. It does seem that your issue is php.ini configuration related.

http://getluky.net/2009/02/24/php-_post-array-empty-although-phpinput-and-raw-post-data-is-available/

Ravi
  • 61
  • 6