Welcome Guest, Not a member yet? Register   Sign In
Undefined property:....
#1

[eluser]bevans[/eluser]
I get an error message that says:
"A PHP Error was encountered
Severity: Notice
Message: Undefined property: Register::$register_model
Filename: controllers/register.php
Line Number: 52

Fatal error: Call to a member function register_insert() on a non-object in D:\EasyEclipse Projects\iFitIgniter\system\application\controllers\register.php on line 52"

What does it mean to have a "Call to a member function register_insert() on a non-object"?

I am doing a registration page.
I have 3 things: a model, a view, and a controller.
The controller loads the view and the model.
The connection to the db works great. The view pages loads correctly and shows what it should. I then fill in the fields (name, email, etc.) BUT when I click submit I get the error.

Will some one please explain what the error means and how to fix it???
Thanks in advance.

Here is the CONTROLLER code.
Code:
class Register extends Controller {

    public $fields = array('firstname','lastname', 'email', 'screenname', 'password');

   function index()
    {
        parent::Controller();
        $this->load->model('register_model');
        $this->load->library('validation');

        $rules['firstname'] = "trim|required|min_length[5]|max_length[12]";
        $rules['lastname'] = "trim|required";
        $rules['eamil'] = "trim|required";
        $rules['screenname'] = "trim|required";
        $rules['password'] = "trim|required|valid_email";

        $this->validation->set_rules($rules);

        $fields['firstname'] = 'firstname';
        $fields['lastname'] = 'lastname';
        $fields['email'] = 'email';
        $fields['screenname'] = 'screenname';
        $fields['password'] = 'password';

        $this->validation->set_fields($fields);

        /*
         *
          if($this->validation->run() == False)
        {
            $this->load->view('register_view');
        }else{
            $this->load->view('');
        }
        */

        $this->load->view('register_view');
    }

    function register_insert()
    {

        $this->load->database();

        //$num_rows =
        $this->register_model->register_insert();

        //$data['num_rows'] = $num_rows;

        $this->load->view('register_view.php');

    }

}


Here is the VIEW code
Code:
<html>
<head>
    <title></title>
</head>

<body>
    <?=$this->validation->error_string; ?>

    <?=form_open('/register/register_insert');?>
        First Name:
        &lt;input type="text" name="firstname" value="&lt;?=$this-&gt;validation->firstname;?&gt;" size="20" />&lt;?=$this->validation->firstname_error; ?&gt;<br />
        Last Name:
        &lt;input type="text" name="lastname" value="&lt;?=$this-&gt;validation->lastname;?&gt;" size="20" />&lt;?=$this->validation->lastname_error; ?&gt;<br />
        Email:
        &lt;input type="text" name="email" value="&lt;?=$this-&gt;validation->email;?&gt;" size="20" />&lt;?=$this->validation->email_error; ?&gt;<br />
        Choose a Screen Name:
        &lt;input type="text" name="screenname" value="&lt;?=$this-&gt;validation->screenname;?&gt;" size="20" />&lt;?=$this->validation->screenname_error; ?&gt;<br />
        Password:
        &lt;input type="password" name="password" value="&lt;?=$this-&gt;validation->password;?&gt;" size="20" />&lt;?=$this->validation->password_error; ?&gt;<br />
        &lt;input type="submit" name="submit" value="Register Now"&gt;
    &lt;/form&gt;

&lt;/body&gt;
&lt;/html&gt;

Here is the MODEL code
Code:
class Register_model extends Model  {

    public $firstname = '';
   public $lastname = '';
   public $email = '';
   public $screenname = '';
   public $password = '';
   public $signupdate = '';

        function register_model()
        {
        parent::Model();
        $this->load->helper('form');
        }

       function register_insert()
         {

        $this->firstname = $_POST['firstname'];
        $this->lastname = $_POST['lastname'];
        $this->email = $_POST['email'];
        $this->screenname = $_POST['screenname'];
        $this->password = $_POST['password'];

        

$sql_query = "INSERT INTO DB ("
                . " EMAIL,"
                . " FIRSTNAME,"
                . " LASTNAME,"
                . " SCREENNAME,"
                . " PASSWORD"
            . " ) VALUES ("
                . " ?,"
                . " ?,"
                . " ?,"
                . " ?,"
                . " ?"
            . " )";


        }

}
#2

[eluser]Negligence[/eluser]
You need to load the model in the register_insert() function in your controller.
#3

[eluser]bevans[/eluser]
[quote author="Negligence" date="1202427382"]You need to load the model in the register_insert() function in your controller.[/quote]

where do I put it?
I tried it at the top of the function right after the opening bracket {. I also tried it at the bottom of the function just before the closing bracket }. Neither place seems to work.
Am I calling it incorrectly?

Code:
function register_insert()
    {
$this->load->model('register_model');
        $this->load->database();

        $this->register_model->register_insert();

        //$data['num_rows'] = $num_rows;

        $this->load->view('register_view.php');

$this->load->model('register_model');
    }
#4

[eluser]tonanbarbarian[/eluser]
you need a constructor for your controller, like you have for the model

Code:
class Register extends Controller {

  function Register() {
    parent::Controller();
  } // Register()
...
#5

[eluser]bevans[/eluser]
[quote author="tonanbarbarian" date="1202437153"]you need a constructor for your controller, like you have for the model

Code:
class Register extends Controller {

  function Register() {
    parent::Controller();
  } // Register()
...
[/quote]



That did it... it works now.
Thank you for your help.




Theme © iAndrew 2016 - Forum software by © MyBB