-2

I am getting the following error: Notice: Undefined variable: POST

   <form action="" method="POST">
your email: <br /><input ="text" name="email" size"30"/><br />
<input type="submit" name="submit" value="Submit" />
</form>
<?php

        $email= $POST['email'];
        $submit =$POST['submit'];
dabollix
  • 47
  • 4
  • Duplicate of [PHP: "Notice: Undefined variable" and "Notice: Undefined index"](http://stackoverflow.com/a/4261200/342740) – Prix Oct 01 '14 at 13:28

5 Answers5

3

you are missing _ it should be $_POST not $POST change them to. it would be better if you use isset or empty while assign value to variable.

  $email= $_POST['email'];
  $submit =$_POST['submit'];
Ram Sharma
  • 8,676
  • 7
  • 43
  • 56
0

Since it's a PHP superglobal (and therefore prefixed with _), it's $_POST.

rodrigorigotti
  • 234
  • 1
  • 8
  • partially right but overlooking something important there even if you write it with `_` as it is you would still get the notice. – Prix Oct 01 '14 at 13:13
  • That's because a given index might not exist in the `$_POST` array. It's better to use something like: `$email = isset($_POST['email']) ? $_POST['email'] : null;`. – rodrigorigotti Oct 01 '14 at 13:15
  • Then you should have updated that to your question as the way it is right now its an incomplete answer or at least mention why it would still produce a notice even with the change from $POST to $_POST. – Prix Oct 01 '14 at 13:16
0

you need to check with empty() or isset() to avoid php notices also use $_POST rather $POST

in php POST method values get by $_POST

if(isset($_POST['submit'])) {    
  $email= (!empty($_POST['email']) ? $_POST['email'] : '');
}
Rakesh Sharma
  • 13,680
  • 5
  • 37
  • 44
0

You need to wrap your code in a conditional that checks if a post request has been made, otherwise the code will run on pageload, when there is no post data:

<?php
if($_SERVER['REQUEST_METHOD']=='POST'){
    //you should also probably check the individual keys exist as well...
    $email= $_POST['email'];
    $submit =$_POST['submit'];
}

Also, as mention by others, php superglobals are prefixed with an underscore, so its $_POST not $POST

Steve
  • 20,703
  • 5
  • 41
  • 67
-1

It's not $POST, it's $_POST, per this answer. PHP superglobals need a _ to be prefixed to the variable name. Per this answer, you should also use isset() to make sure that your variables are declared first.

Community
  • 1
  • 1
APerson
  • 8,140
  • 8
  • 35
  • 49