welcome to WebmasterWorld, drgonzo!
you must declare your variables within the same scope in which they are referred.
for example if you did this:
$variable = 1;
then "$variable" would be declared within the scope of the "if" and the "$variable" in the assignment statement would be an undeclared variable.