I coded a form script on my system, it runs IIS. When I moved it to test, that server is running Apache, and now I'm getting all sorts of 'Undefined index' errors.
Notice: Undefined index: user_name in c:\program files\apache group\apache\htdocs\poker\leagueman.php on line 52
I get the erros when I first load the page. I've looked at the variables coming into the page using print_r($GLOBALS), and it shows an empty array when the page first loads. That's fine. However, I'm referencing the variables inside my form. The form looks like this:
echo '<INPUT TYPE="TEXT" NAME="user_name" VALUE="' . $_POST['user_name'] . '" SIZE="20" MAXLENGTH="20">';
I've found a work around using isset.
if (isset($_POST['user_name'])) {
$user_name = $_POST['user_name'];
}
else {
$user_name = NULL;
}
If I use the above code to handle it, now I have to go in and change every form element from $POST['user_name'] to $user_name, and also change any variables being passed into a function from $POST['user_name'] to $user_name.
I really don't want to have to rewrite my code for every form variable. Is there an easier way to get around this?
I know about using '@' in the front to suppress the error messages, but is that really the standard?
What is the best way to handle these types of messages?
Thanks!
-J