9three Posted September 16, 2009 Share Posted September 16, 2009 Hey, This is part of my login script: if ($row = $objStatement->fetch()) { if ($row['verified'] == 'Y') { session_start(); session_regenerate_id(); $_SESSION['username'] = $row['email']; $_SESSION['user_id'] = $row['id']; $_SESSION['fullname'] = $row['name'].' '.$row['lname']; $_SESSION['fname'] = $row['name']; $_SESSION['lname'] = $row['lname']; $this->id = $_SESSION['user_id']; $this->fullname = $_SESSION['name'].' '.$_SESSION['lname']; $this->username = $_SESSION['username']; $this->fname = $_SESSION['fname']; $this->lname = $_SESSION['lname']; I tried this but it didn't work. $this->setFirstname($_SESSION['fname']); //And this too $this->setFirstname($row['name']); Simple setters/getters public function setFirstname($strFirstname) { $this->fname = $strFirstname; } public function getFirstname() { return $this->fname; } If I try to use my getFirstname method it will return a null value. When I initiate the class as an object it also returns null. The only thing I got working was doing it like this: public function getFirstname() { return $_SESSION['fname']; } I also did this in the HTML: $objUser->setFirstname('Yes'); echo $objUser->getFirstname(); The output was Yes. So it works through the HTML side, but not the class itself. Can someone lend a hand? Quote Link to comment https://forums.phpfreaks.com/topic/174500-setter-not-storing-value/ Share on other sites More sharing options...
sKunKbad Posted September 16, 2009 Share Posted September 16, 2009 Are you declaring your variables at the top of your class? Like this: public $fname = ''; Quote Link to comment https://forums.phpfreaks.com/topic/174500-setter-not-storing-value/#findComment-919740 Share on other sites More sharing options...
9three Posted September 16, 2009 Author Share Posted September 16, 2009 Yes. private $fname; etc.. Quote Link to comment https://forums.phpfreaks.com/topic/174500-setter-not-storing-value/#findComment-919813 Share on other sites More sharing options...
sKunKbad Posted September 16, 2009 Share Posted September 16, 2009 Hard to say what is going wrong without seeing more code. Quote Link to comment https://forums.phpfreaks.com/topic/174500-setter-not-storing-value/#findComment-919819 Share on other sites More sharing options...
seventheyejosh Posted September 17, 2009 Share Posted September 17, 2009 Is there something in session? Are you doing session_start()? Quote Link to comment https://forums.phpfreaks.com/topic/174500-setter-not-storing-value/#findComment-919826 Share on other sites More sharing options...
9three Posted September 17, 2009 Author Share Posted September 17, 2009 Yes, I'm doing session_start(see the code) and in every page as well. Quote Link to comment https://forums.phpfreaks.com/topic/174500-setter-not-storing-value/#findComment-919852 Share on other sites More sharing options...
Recommended Posts
Join the conversation
You can post now and register later. If you have an account, sign in now to post with your account.