Please wrap your code in [php] [/php] tags --- it helps with readability and the colored syntax highlighting will help expose common errors.
An "undefined variable" error is a warning, but it not fatal. You could adjust your error_reporting level and it wouldn't show up ---- BUT, it's there to allow you to write more secure code. You should, as a rule, keep strict track of where your data is coming from, and, by extension, you should declare variables and assign a value before use ... if you do this, those pesky errors will go away.
Basically, if PHP does something with a variable that didn't previously exist in an assignment statement ... you get the error.
<?php
$foo=''; // you can initialize a local variable like this
$foo.=`hostname`; // no errors here...
if (isset($_GET['bar])) { // if it's coming from somewhere else, use isset()
$bar=mysql_escape_string($_GET['bar']); // and you should probably clean it up...
} // in this case, we'll just use mysql_escape_string()
if ($bar) { // now we won't received an "undefined variable" error...
do_something();
}
if($garply) { // you'll be warned here, because you're evaluating a "brand new" variable
something_else();
}
?>