the vars still have to be defined inside the function. hence the global definitions Weedpacket stated.. u can pass the vars into the function by typeing function($var, $var, $var, etc) that way inside the function you can just say something like..
function($a)
{
$ainfunction = $a
}
i believe that's what's wrong :S