Welcome Guest, Not a member yet? Register   Sign In
Fatal error: Call to undefined function insert() in C:wamp/www/app/models/users_model.php on line 48
#1

[eluser]cobolCowboy[/eluser]
:grrr:
CI v.2.1.0
Apache v2.2.21
PHP v5.3.10
MySQL v5.5.20

I'm trying to insert the new registration data on the 'users' table.
the form passes validation:

Code:
If ($this->form_validation->run() === FALSE) :
      $data['title']   = '.com | Sign Up';
      $data['page']   = 'signup';
      $this->load->view('template', $data);
else :
      $data['id']       =  NULL;
      $data['name']     =  $_POST['name'];
      $data['email']    =  $_POST['email'];
      $data['password'] =  $_POST['password'];
      $data['status']   = 'inactive';
      if  ($_POST['newsletter'] === 'Y') :
        $data['newsletter'] = 'Y';
      else :
        $data['newsletter'] = 'N';
      endif;
      $data['ts']     =  NULL;
      $data['group']  =  9;
      $this->load->model('users_model', 'user');
      $this->user->insert($data);
endif;


So from here, we go to the users_model insert function.

Code:
class Users_model extends CI_Model {

   var $id          = '';
   var $name        = '';
   var $email       = '';
   var $password    = '';
   var $status      = '';
   var $newsletter  = '';
   var $ts          = '';
   var $group       = '';

    function __construct()
    {
  // Call the Model constructor
        parent::__construct();
  
    }

    function insert($data)
    {
        $this->id         = $data['id'];
        $this->name       = $data['name'];
        $this->email      = $data['email'];
        $this->password   = $data['password'];
        $this->status     = $data['status'];
        $this->newsletter = $data['newsletter'];
        $this->ts         = $data['ts'];
        $this->group      = $data['group'];
  var_dump($this);
  echo BASEPATH;
$this->db>insert('users', $this);
    }
}

and despite auto-loading the database library, and setting active record to TRUE
I continue to get this error; here is my var_dump($this) together with the base path whic is correct the error message I'm getting.

Quote:object(Users_model)[18]
public 'id' => null
public 'name' => string 'sneaky pete' (length=11)
public 'email' => string 'sneaky_pete@yahoo.com' (length=21)
public 'password' => string '6f92b498895e8f5c93c24ad3797e7d9c' (length=32)
public 'status' => string 'inactive' (length=8)
public 'newsletter' => string 'Y' (length=1)
public 'ts' => null
public 'group' => int 9

C:/wamp/www/sys/

( ! ) Fatal error: Call to undefined function insert() in C:\wamp\www\app\models\users_model.php on line 48
Call Stack
# Time Memory Function Location
1 0.0011 390912 {main}( ) ..\index.php:0
2 0.0057 463928 require_once( 'C:\wamp\www\sys\core\CodeIgniter.php' ) ..\index.php:202
3 0.0980 3486576 call_user_func_array ( ) ..\CodeIgniter.php:359
4 0.0980 3486624 Signup->index( ) ..\CodeIgniter.php:359
5 0.1107 3990064 Users_model->insert( ) ..\signup.php:37



line 48 in the users_model:
Code:
$this->db>insert('users', $this);

It's prolly something stupid. I just can't see it.












#2

[eluser]InsiteFX[/eluser]
It's expecting an associate array to be passed to it not an object, $this is an object that's why you are getting the error!

Change $this to $data.

Or read the CodeIgniter Users Guide on how to pass an object.
#3

[eluser]aquary[/eluser]
CI' AR do accept object for inserting, although using $this for inserting might cause error, but it was not related to this case.

cobolCowboy, look closely at the line with error.

Code:
$this->db>insert('users', $this);

Have you seen a character missing ? something after "db"......The error message is already clear. "Call to undefined function insert()"....

Anyway, in this format, as I stated earlier, you might got an error in the query of PHP error. Due to $this itself refer to the users model itself... which contains all the methods. It may or may not be error since this is a weird case I've never done/seen before, but I'd suggest you to create a new variable instead, like $insert or $user.
#4

[eluser]Abdul Malik Ikhsan[/eluser]
try to change insert() function in model to another for avoid collision function, for example :
Code:
public  function insertIntoTable($data)
  {
    
  }

#5

[eluser]cobolCowboy[/eluser]
okay Gang,

Just flew back in, and boy are my arms tired!!

Everybody was a little correct, and here's the original culprit line in the model.

Code:
$this->db>insert('users', $this);

there was a missing dash.

V
Code:
$this->db->insert('users', $this);

Many thanks,







Theme © iAndrew 2016 - Forum software by © MyBB