Jump to content

Returning variables


johnslater

Recommended Posts

// Is there a user cookie set?
function cookie()
{
if (isset($_COOKIE["userlogin"]))
{
$cookie_acti = $_COOKIE["userlogin"];

$result = mysql_query("SELECT * FROM users WHERE activationid='$cookie_acti'");
while($row = mysql_fetch_array($result))
{
$cookie_username = $row['username'];
$cookie_fname = $row['fname'];
$cookie_lname = $row['lname'];

return $cookie_username;
return $cookie_fname;
return $cookie_lname;
}
}

else
{
$cookie_username = "Guest";
$cookie_fname = "Guest";
$cookie_lname = "";
}

} // End cookie function

cookie();

 

I have once used a different method to get 1 item from a database but i dont seem to be able to find it, if you could post another emthod that you think may fix the while loop then that would be great

Link to comment
https://forums.phpfreaks.com/topic/89238-returning-variables/#findComment-456946
Share on other sites

Is there anyway i can set up all of these varibles then just call them as normal like $cookie_username

 

I currently have this...

$cookie_fname = $cookie_fname=cookie();
$cookie_lname = $cookie_lname=cookie();
$cookie_username = $cookie_username=cookie();
$cookie_set = $cookie_set=cookie();

 

But for some reason the top one cancels out all of the others

Link to comment
https://forums.phpfreaks.com/topic/89238-returning-variables/#findComment-456976
Share on other sites

After slightly more testing and after putting this at the end of my function like you suggested it appear it only works with one value however i need to call several values from the same function.

 

return $cookie_username;

return $cookie_fname;

return $cookie_lname;

return $cookie_set;

 

Only the top one (username) is being used and no matter which value i try to call it always calls username

Link to comment
https://forums.phpfreaks.com/topic/89238-returning-variables/#findComment-456980
Share on other sites

Archived

This topic is now archived and is closed to further replies.

×
×
  • Create New...

Important Information

We have placed cookies on your device to help make this website better. You can adjust your cookie settings, otherwise we'll assume you're okay to continue.