Question: I've started to learn PHP. `$_POST` variable is working in some of files, that I'm even able to post the data obtained through `$_POST` to database.

Strangely, `$_POST` is not working in few files. I mean its inconsistent.

Below is the html:

```
<html>
<title></title>
<head>
</head>
<body>
 <form method="POST" action="addemail.php">
<label for="firstname">First name:</label>
<input type="text" id="firstname" name="firstname" /><br />
<label for="lastname">Last name:</label>
<input type="text" id="lastname" name="lastname" /><br />
<label for="email">Email:</label>
<input type="text" id="email" name="email" /><br />
<input type="submit" name="submit" value="Submit" />
</form>
</body>
</html>

```

And below is the PHP code:

```
<html>
<body>

<?php 
    $first_name = $_POST['firstname'];
    $last_name = $_POST['lastname'];
    $email = $_POST['email'];   

    print($first_name);

    $dcf = mysqli_connect('localhost','uname','XXX','elvis_store') 
                 or die('Error connecting to MYSQL Server.');

    $query = "INSERT INTO email_list (first_name, last_name, email) " .
                    "VALUES ('$first_name', '$last_name', '$email')";

    $result = mysqli_query($dcf, $query);

    mysqli_close($dcf);

?>

</body>
</html>

```

Any pointers to overcome this issue will be of great help.

Answer: 
$\_POST should not have any consistency issues. It could be many things:

**Possible Code Errors**

1. You misspelled a key name
2. Ensure that you actually set the values
3. Perhaps you are passing some variables via the URL www.example.com?var=x (GET) and then trying to reference `$_POST['var']` instead of `$_GET['var']`
4. Perhaps you did not actually POST to the page. If you are submitting from a form ensure the `method` attribute is set to `POST` (method="POST")

I'm sure there are many other possibilities (like your dev environment), but it is unlikely that `$_POST` is inconsistent. I would need to see more code on your end.

**Possible Environment/Usage Errors**

1. Ensure WAMP is started (It doesn't always auto start)
2. Ensure you are accessing your page via `http://localhost/path/file.php` and not trying to open it up straight from the folder it is in i.e. `C:\path\file.php`. It must run through Apache.

i.e. Is it only `$_POST` that is not working? if you type `<?php echo "TEST"; ?>` in your script, doest it echo out `TEST`?
you have to check the name of field in HTML file ,which you are going to post.so,may be there is a problem in your field name in HTML file.look it carefully.