You should never attempt to directly access external data without first verifying that it exists. For example, instead of writing:
$user = $_POST['user'];
, I tend to do something like:
$user = (isset($_POST['user']) ? $_POST['user'] : NULL);
This uses the ternary operator for brevity; it's the same as writing:
if(isset($_POST['user']))
$user = $_POST['user'];
else
$user = NULL;
The point is, use [man]isset/man (or [man]empty/man, or any method you desire) to verify that external data exists before you attempt to reference it.
EDIT: Also, when posting PHP code, please use the board's [noparse]
..
[/noparse] bbcode tags as they make your code much easier to read and analyze.