2

i have a login function in a seperate script(main.php) which is like the below

public function login($username,$password) {
$linkingcon = $this->getConnection();
$sqlquery = "SELECT ac.userID,ac.name,us.usertype FROM users us JOIN accounts ac ON us.userID = ac.userID WHERE us.username='$username' AND us.password='$password';";
$result = mysql_query($sqlquery , $linkingcon);
$this->throwMySQLExceptionOnError($linkingcon);
$row = mysql_fetch_array($result);
$survey = new stdClass();
if($row) {
    $res->userID = (int)$row['userID'];
    $res->name = $row['name'];
    $res->usertype = (int)$row['usertype'];
            $string = rand() . 'SurveyLand' . rand() . $username. $password;
        $_SESSION['SURVEYLAND_KEY'] = md5($string);
} else {
    $res = false;
}
return $res;

}

and im calling the above login function from another script but i am currently unable to call the "usertype" variable of the above function... below is the function that i have written to call the "usertype", can anybody check what is wrong with the below function

function login($parameters) {
$main = new Main();
$log = $main->login($parameters["username"], $parameters["password"]);
if($log != false){
    $_SESSION['usertype'] = $res->usertype;
    print_r($_SESSION);
    }
return $log;

}

2
  • what is the error you are getting? and what is "$pro" in your second code? Commented Aug 22, 2014 at 5:30
  • have you tried to print $res->usertype; over there? and is it print value? Commented Aug 22, 2014 at 5:38

1 Answer 1

1

Try changing $res to $log in the second method. $res is the variable name you use in the first method, but is out of scope in the second method. However you assign the response of the first method (ie. $res) to $log in the second method.

function login($parameters) {
  $main = new Main();
  $log = $main->login($parameters["username"], $parameters["password"]);
  if($log != false){
    $_SESSION['usertype'] = $log->usertype;
    print_r($_SESSION);
  }
  return $log;
}
Sign up to request clarification or add additional context in comments.

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.