Welcome Guest, Not a member yet? Register   Sign In
Call to a member function on null error
#1

I am beginners in CodeIgniter. When I am trying to run an application. Its show the error "Call to a member function on null error" My code as given below: 
Controller : Hello.php
<?php
  class Hello extends CI_Controller
  { 
      public function _construct()
  {
  parent::_construct();
 
  $this->load->database();
 
  $this->load->model('Hello_model');
  }  
 
  public function savedata()
  {
  $this->load->view('registration');
 
  if($this->input->post('save'))
  {
 
  $nm=$this->input->post('name');
  $mob=$this->input->post('mobile');
  $msg=$this->input->post('message');
 
  $this->Hello_model->saverecords($nm,$mob,$msg);

 
  echo "Record Saved";
  }
  }
  }
?>

View: registration.php
<!DOCTYPE html>
<html>
<head>
<title>Registration form</title>
</head>

<body>
<form method="post">
<table width="600" border="1" cellspacing="5" cellpadding="5">
  <tr>
    <td width="230">Enter Your Name </td>
    <td width="329"><input type="text" name="name"/></td>
  </tr>
  <tr>
    <td>Enter Your Mobile Number </td>
    <td><input type="text" name="mobile"/></td>
  </tr>
  <tr>
    <td>Enter the Message </td>
    <td><input type="text" name="message"/></td>
  </tr>
  <tr>
    <td colspan="2" align="center"><input type="submit" name="save" value="Save Data"/></td>
  </tr>
</table>

</form>
</body>
</html>

Model: Hello_Model.php
<?php
class Hello_model extends CI_Model
{

function saverecords($name,$mobile,$message)
{
$query="insert into 18sms values('','$name','$mobile','$message')";
$this->db->query($query);

}

}
?>

I am using CodeIgniter 3.1.10  and Laragon lite 4.0.111 
Please help.
Reply




Theme © iAndrew 2016 - Forum software by © MyBB