last day (14 days later) » 

5:09 AM
0
A: Accessing object's properties in an array php

Kyle EmmanuelYou can try this, since using $_SESSION['customer'] contains a Customer object. $customer = $_SESSION['customer']; $username = $customer->getUsername();

 
Throws an error Fatal error: main(): The script tried to execute a method or access a property of an incomplete object. Please ensure that the class definition "Customer" of the object you are trying to operate on was loaded _before_ unserialize() gets called or provide a __autoload() function to load the class definition
 
That must mean that object's contents are private.
Try casting it @Shashank.
 
Could you please explain @kyle
 
It simply means that your Customer object is nothing but an object in its incomplete state while being stored in $_SESSION. refer to this: stackoverflow.com/questions/132194/…
 
I am trying to workaround it by storing only the customerid in the session and then re-firing the query on my DB, but still i am unable to get the value from the session, The var_dump is string (4) 1019. How do I can i retrieve only 1019?? @kyle
 
5:10 AM
Hello.
Please post your updated $_SESSION's content
 
string(4) "1019"
@kyle
 
5:30 AM
Did you store it like this: $_SESSION['customer_id'] = VALUE ?
 
I am checking for username and password from mysql database which returns only the userid field
so now I am setting $_SESSION['customer'] = userid
Here is the code for returning userID `public static function loginAction($username, $password) {
$db = Databases::connectDB();
$query = 'select * from tbl_customer where username=:username and password=:password';
$stm = $db->prepare($query);
$stm->bindParam(':username', $username, PDO::PARAM_STR, 50);
$stm->bindParam(':password', $password, PDO::PARAM_STR, 50);
$stm->execute();
$result = $stm->fetch();

if ($result == null) {
$record = null;
$id = null;
} else {
$record = new Customer($result['customerid'], $result['firstname'], $result['lastname'], $result['dob'], $result['address1'], $r
@kyle
On Login Page :
$customerid = Customer_DB::loginAction($username, $password);
$_SESSION["customer"] = $customerid;
 
5:47 AM
@KyleEmmanuel you there buddy?
 
6:16 AM
Yeah. I'm a little busy right now.
 

last day (14 days later) »