Jump to content

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

This thread is more than a year old. Please don't revive it unless you have something important to add.

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.

Guest
Reply to this topic...

×   Pasted as rich text.   Restore formatting

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

×
×
  • 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.