Welcome Guest, Not a member yet? Register   Sign In
undefined variable
#1

Hi Friends,

Good day!

I am asking for help.

I just started learning code igniter.

and have some source that I followed.

during the testing.

I encountered undefined variable

on the following.
please see below code


Quote:<?php
defined('BASEPATH') or exit('No Direct Script Access Allowed');



class Users_model extends CI_Model{

   //Declares Private Variable

   private $_userID;
   private $_name;
   private $_userName;
   private $_email;
   private $_password;
   private $_status;
   
   public function setUserID($userID) {
       $this->$_userID = $userID;
   }

   public function setEmail($email) {
       
       $this->$_email = $email;
   }

   public function setPassword($password) {
       $this->$_password = $password;
   }

   public function getUserInfo(){
       $this->db->select(array('u.user_id','u.uname','u.email'));
       $this->db->from('user as u');
       $this->db->where('u.user_id',$this->_userID);
       $query = $this->db->get();
       return $query->row_array();
   }

   function login(){
       $this->db->select('user_id','name','email');
       $this->db->from('user');
       $this->db->where('email', $this->$_email);
       $this->db->where('password', $this->$_password);
       $this->db->limit(1);
       $query = $this -> db ->get();
       if($query ->num_rows() == 1){
           return $query->result();  
           } else {
               return false;
           }

       }    
}


?>


also below is the error


Quote:A PHP Error was encountered

Severity: Notice

Message: Undefined variable: _email

Filename: models/Users_model.php

Line Number: 23

Backtrace:

File: D:\xampp\htdocs\webdev\msit\application\models\Users_model.php
Line: 23
Function: _error_handler

File: D:\xampp\htdocs\webdev\msit\application\controllers\Users.php
Line: 65
Function: setEmail

File: D:\xampp\htdocs\webdev\msit\index.php
Line: 315
Function: require_once

I encountered undefined variable on the following

Message: Undefined variable: _email
Message: Undefined variable: _password
Message: Undefined property: Users::$users
and also
Message: Call to a member function login() on null


Thank you in advance
Reply
#2

1) Try to avoid code coloring in your posts, so it is easier to read!
2) You are referencing the variable wrong ... should be "$this->_email"
"$this-$_email" substitutes the value of "$_email" (which is not defined) as the name of the property in "$this".
Reply
#3

Hi ciaadmin,

thank you the help.

I apologize for the post coloring.

by the way, this really help and solve my issue.

Best,
Reply




Theme © iAndrew 2016 - Forum software by © MyBB