0

PHP Error was encountered Severity: Notice Message: Undefined property: Registerform::$db Filename: core/Model.php Line Number: 51 controller file:

A PHP Error was encountered

Severity: Notice

Message: Undefined property: Registerform::$db

Filename: core/Model.php

Line Number: 51

controller file:

<?php
class Registerform extends CI_Controller {
    function __construct() {
        parent::__construct();
        $this->load->model('Registerform_model');
    }

    public function index() {

        //$this->load->database();

        $this->load->helper("form");
        $this->load->library("form_validation");
        $this->form_validation->set_rules("first", "First Name","required");
        $this->form_validation->set_rules("last", "Last Name","required");
        $this->form_validation->set_rules("email", "Email Address","required|valid_email");
        $this->form_validation->set_rules("password", "Password","required");
        $this->form_validation->set_rules("phone", "Phone Number","required");
        $this->form_validation->set_rules("city", "City","required");
        $this->form_validation->set_rules("addrss", " Your Address","required");
        if ($this->form_validation->run() == false) {
            $this->load->view("registerform_view");
        } else {
            $first = $_POST["first"];
            $last = $_POST["last"];
            $email = $_POST["email"];
            $password = $_POST["password"];
            $phone = $_POST["phone"];
            $city = $_POST["city"];
            $addrss = $_POST["addrss"];
            $data = array(
                      'first'=>$first,
                      'last'=>$last,
                      'email'=>$email,
                      'password'=>$password,
                      'phone'=>$phone,
                      'city'=>$city,
                      'addrss'=>$addrss
             );                       

            //$data="insert into address (first_name,last_name,email,password,phone,city,add) values('$first','$last','$email','$password','$phone','$city','$add')";

             $gg = $this->Registerform_model->insert_address($data);
             echo $gg;
             $this->load->view("registerformsuccess");

        }
    }
}
?>

model file:

<?php
class Registerform_model extends CI_Model {
    function __construct() {
        parent::__construct();
    }

    public function insert_address($data){                  
        $this->db->insert("address", $data);                    
    }
}
?>

view file:

<?php               
echo validation_errors();           
echo form_open("Registerform");
?>
<label for="first">First Name</label>
<input type="text" name="first" id="first"><br>

<label for="last">Last Name</label>
<input type="text" name="last" id="last"><br>

<label for="email">Email Address</label>
<input type="text" name="email" id="email"><br>

<label for="password">Password</label>
<input type="password" name="password" id="password"><br>

<label for="phone">Phone</label>
<input type="text" name="phone" id="phone"><br>

<label for="city">City Name</label>
<input type="text" name="city" id="city"><br>

<label for="addrss">Your Address</label>
<input type="text" name="addrss" id="addrss"><br>

<input type="submit" name="submit" id="submit" value="Submit">
<?php echo form_close(); ?>
4
  • you should change all your $_POST to CI's $this->input-post()
    – CodeGodie
    Mar 9, 2015 at 21:20
  • is address spelled the right way?. Can you provide your MySql data structure?
    – CodeGodie
    Mar 9, 2015 at 21:28
  • 1
    You have not loaded your database.
    – Joerg
    Mar 9, 2015 at 21:32
  • Your not loading your database as @Joerg suggest's. go to application/config/autoload.php and make sure you have it set to autoload $autoload['libraries'] = array('database')
    – Philip
    Mar 9, 2015 at 22:51

2 Answers 2

1
<?php
class Registerform_model extends CI_Model {
    function __construct() {
        parent::__construct();

        }
           public function insert_address($data){   
                 $this->load->database();               
        $this->db->insert("address", $data);                    
    }
        }
?>

Its work for me now.

0

You have to load database. Put this line in model file constructor function:

 $this->load->database();
0

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Not the answer you're looking for? Browse other questions tagged or ask your own question.