1

I am new to php programming. I have been trying to learn from w3 schools. I have installed phpstorm on my mac. I have been learning forms. the code is below

Form:

<form action="welcome.php" method="post">
    Name: <input type="text" name="name" id="name"> <br>
    E-mail: <input type="text" name="email" id="email"><br>
    <input type="submit">
</form> 

Message board:

Welcome <?php echo $_POST["name"]; ?><br>
Your email address is: <?php echo $_POST["email"]; ?>

When I try and use post on the form, I get an error

Welcome 
Notice: Undefined index: name in /Users/chris/PhpstormProjects/three/welcome.php on line 4

Your email address is: 
Notice: Undefined index: email in /Users/chris/PhpstormProjects/three/welcome.php on line 5

But when I use get the code works perfectly. I use a Mac, I have tried changing from MAMP to XAMPP, have run the code in xampp and mamp and still nothing happens. I am all out of ideas, can anyone help ?

Update

This is not like any other problem on stack overflow ( believe me I've checked :-) )

From what can see , the HTML form is not writing to post which is odd as thats what I thought it should do , has anyone else come across this in phpstorm ?

Many thanks again

  • you can set the desired method in your form (`method='POST'`)! Only one will work at a time (in normal cases. Yes, there are cases where both variables are filled). – Jeff Jun 16 '16 at 16:19
  • 2
    Have you actually submitted the form? – Jonnix Jun 16 '16 at 16:19
  • Possible duplicate of [Form GET works, Form POST does not](http://stackoverflow.com/questions/5522171/form-get-works-form-post-does-not) – Jeff Jun 16 '16 at 16:20
  • Is the form *also* on `welcome.php` or are those 2 different pages? – gen_Eric Jun 16 '16 at 16:20
  • if this didn't help you'd have to show your code (html-form and php) – Jeff Jun 16 '16 at 16:21
  • Possible duplicate of [PHP: "Notice: Undefined variable" and "Notice: Undefined index"](http://stackoverflow.com/questions/4261133/php-notice-undefined-variable-and-notice-undefined-index) – The Codesee Jun 16 '16 at 16:26
  • 1
    `learn from w3 schools` - don't do that. their code is crap... – Marc B Jun 16 '16 at 16:38
  • 1
    Rocket- These are 2 different pages :-), Jon Stirling, I have submitted the form – Chris Millington Jun 16 '16 at 16:42
  • A lot of folks are asking if I have defined a variable, am not sure how I would do that from an html form !!! – Chris Millington Jun 16 '16 at 16:43
  • Check in your browser's debugging tools (in its network pane) or using a tool like Fiddler or Wireshark to make sure the browser is sending the POST data. If it is, then the issue might be with PHP or apache (or nginx or whatever). Are there any `.htaccess` files or anything weird with your server config? – gen_Eric Jun 16 '16 at 17:02
  • Have downloaded wireshark. When I load and submit the form, am getting a lot of loopback, but nothing else – Chris Millington Jun 16 '16 at 17:16

1 Answers1

0

After searching a lot of forums, there appears to be bugs with the internal PhpStorm web server that prevent posts from working, although, I am not certain of the circumstances. I wasn't able to get simple or complex posts to work with my current setup (PHP 7 with PhpStorm 2016.2 built on July 12, 2016).

Solution was to use a proper web server instead of the internal one. To do this:

  1. Define Deployment entry (Tools --> Deployment --> Configuration). Set the type to be either "In place" or "Local or mounted folder" and ensure your web server to serve up your project files.
  2. Configure the remaining items by providing URL details for your web server configuration.
  3. Click on "Use this server as default" on the Mappings tab.

Now the IDE will use that deployment option for Run & Debug actions for the current project and any future ones. You may still need to reconfigure any other pre-existing projects you have manually.

I note that this issue can result in multiple errors including bad gateway, page not found and your undefined index error, but all three should be fixed by the same solution.

danlynn
  • 143
  • 1
  • 5
  • Please answer the question _directly_ in you answer, instead of linking to external websites. This will increase the quality of your post, both for the OP and new users with the same question. – Nander Speerstra Jul 25 '16 at 13:45