Question: I have a full working php script for user activation that I wrote. Fully working in a sense that it displays no errors while on my actual web hosting, although when I am working in WAMP2 I get errors such as these.

```
Notice: Undefined index: type in C:\wamp\www\activate.php on line 4
Notice: Undefined index: username in C:\wamp\www\activate.php on line 5
Notice: Undefined index: gender in C:\wamp\www\activate.php on line 6
Notice: Undefined index: formvalue in C:\wamp\www\activate.php on line 29

```

I know what the problem is, it is because the page activation.php is both for the form submission from create.php (the form on create.php has a hidden value of 1 and if it exists then the form is submitted into the mysql db) and if the form value is not present then the user is activating their account.

When the user is activating, the variables that I have defined using $\_POST and the hidden form value of 1 are not defined which is causing the errors. 

My question is why are these errors not displayed when my pages are loaded on my actual hosting but are present in WAMP2? And do these errors matter, is it bad practice to have undefined variables? And if so how do I overcome the problem?

Thanks and I hope I explained that all ok.

Answer: 
> 
> is it bad practice to have undefined
>  variables?
> 
> 
> 

Yes

> 
> how do I overcome the problem?
> 
> 
> 

By not using variables that don't exist.

Or by using variables that have been initialized with a default value, if the expected value has not been provided.

For example :

```
if (isset($_POST['login'])) {
    $login = $_POST['login'];
} else {
    $login = '';
}

```

Or, using the ternary operator, to get something shorter :

```
$login = isset($_POST['login']) ? $_POST['login'] : '';

```

> 
> why are these errors not displayed
>  when my pages are loaded on my actual
>  hosting but are present in WAMP2?
> 
> 
> 

If can be because are displayed on one server, and not on the other -- see [**`display_errors`**](http://fr.php.net/manual/en/errorfunc.configuration.php#ini.display-errors).

Or it can be because the [**`error_reporting`**](http://fr.php.net/manual/en/errorfunc.configuration.php#ini.error-reporting) level is not the same on the two servers.

Typically, your development server is configured to report notices *(see [**`E_NOTICE`**](http://fr.php.net/manual/en/errorfunc.constants.php))*, and to display errors -- which makes things easier when it comes to finding the cause of some problems.
<http://php.net/manual/en/errorfunc.configuration.php> - display\_errors and display\_startup\_errors  

Also what I want to say - its good practice to check if array key exists:

```
$login = isset($_POST['login']) ? $_POST['login'] : NULL;

```