Jump to content

Setter not storing value


9three

Recommended Posts

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?

Link to comment
https://forums.phpfreaks.com/topic/174500-setter-not-storing-value/
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.