ok, the issue here is called variable scope. In php, functions have their own variables and they do not share with variables defined outside the function unless you tell that function to get them the global scope. Let me demonstrate:
$myVar = 'Test1';
testScope(); // echos null;
function testScope()
{
echo $myVar;
}
Why did this not work? Well, inside the function, testScope, it can not see variables that were defined outside the function. THIS IS FOR YOUR PROTECTION! Trust me.
Any variable not defined in a function or method (if working with classes) is called a global variable (for future reference).
ok, so how could we make this work? Well, many ways but here is one:
$myVar = 'Test1';
testScope(); // echos Test1;
function testScope()
{
global $myVar;
echo $myVar;
}
now, this works but is evil. Using globals is really bad. Why? Well, this script is simple, but lets say your script gets complicated. Well, somewhere in the script, $myVar could change and you would have a hell of a time tracking down where it changed, because it could happen anywhere in the global scope (even in files you are including in!) so beware, this is bad.
The better option is to pass it in everytime you need it:
testScope( 'Test1' ); // echos Test1;
function testScope( $myVar )
{
echo $myVar;
}
or better yet, encapsulate it in an object (I wont go into that).
So to answer your question, It looks like your function needs to return the results of your query to the global scope like so:
function lookupData()
{
.... do your select stuff here
return $row;
}
$row = lookupData();
echo "<input name = \"userName\" INPUT type =\"text\"";
echo "value = \"";
echo $row["userName"];
echo " \" name=\"userName\" size=\"25\" maxlength=\"60\">";
Hope this helps,
Mike