I am trying to return the current username. I get the user name from the URL and access by $_GET['user'] method.
But when i try with the get method it will not return the name, instead its returning empty.
echo $_GET['user']; // giving myname
$userName=$_GET["user"];
function getUserName()
{
global $userName;
if(isset($userName)){
return $userName;
}else{
return "defaultuser";
}
}
I tried this, too:
$userName="".$_GET['user']."";
But when I give simply $userName="myname"; its working. So is there any problem in this line $userName=$_GET["user"];.
Try this
http://www.mysite.com/index.php?user=myname
Method 1 :
Method 2 :
Second Method uses the ternary operator. it does the exact same thing as the first method.
P.S : If you consider using above code for database querying do not forget to use
mysql_real_escape_string()