0

guys if i change my hosting i get a error in my local ampps host i not have not one problem now i see this error everithing is same php version is 7.1 and in local is 7.1 but why i get this error? This is error code :

Fatal error: Uncaught Error: Call to a member function userDetails() on null in /home/root/requests/index.php:14 Stack trace: #0 {main} thrown in /home/root/requests/index.php on line 14

this is my function in top of index.php

<?php
include('config.php');
include('session.php');
$userDetails=$userClass->userDetails($session_uid);

this is my session.php code

<?php
if(!empty($_SESSION['uid']))
{
$session_uid=$_SESSION['uid'];
include('userClass.php');
$userClass = new userClass();
}
if(empty($session_uid))
{
$url=BASE_URL.'/login.php';
header("Location: $url");
}
?>

this is my userClass.php code :

<?php
class userClass
{
/* User Login */
public function userLogin($usernameEmail,$password)
{
try{
$db = getDB();
$hash_password= hash('sha256', $password); //Password encryption 
$stmt = $db->prepare("SELECT uid FROM users WHERE (username=:usernameEmail or email=:usernameEmail) AND password=:hash_password"); 
$stmt->bindParam("usernameEmail", $usernameEmail,PDO::PARAM_STR) ;
$stmt->bindParam("hash_password", $hash_password,PDO::PARAM_STR) ;
$stmt->execute();
$count=$stmt->rowCount();
$data=$stmt->fetch(PDO::FETCH_OBJ);
$db = null;
if($count)
{
$_SESSION['uid']=$data->uid; // Storing user session value
return true;
}
else
{
return false;
} 
}
catch(PDOException $e) {
echo '{"error":{"text":'. $e->getMessage() .'}}';
}

}

/* User Details */
public function userDetails($uid)
{
try{
$db = getDB();
$stmt = $db->prepare("SELECT email,username,name FROM users WHERE uid=:uid"); 
$stmt->bindParam("uid", $uid,PDO::PARAM_INT);
$stmt->execute();
$data = $stmt->fetch(PDO::FETCH_OBJ); //User data
return $data;
}
catch(PDOException $e) {
echo '{"error":{"text":'. $e->getMessage() .'}}';
}
}
}
?>
Besa Besa
  • 11
  • 1

1 Answers1

0

Did you defined $userClass, if not then you should make an object the userClass that you are using here then call the method inside that class and it will work.

engrhussainahmad
  • 1,008
  • 10
  • 19