Welcome Guest, Not a member yet? Register   Sign In
pbm in inserting
#1

[eluser]Unknown[/eluser]
can anyone pls tell me wat is the pbm in the code for inserting a row.
my controller :
<?php
class Form extends Controller{
function Form(){
parent::Controller();
$this->load->helper('url');
$this->load->helper('form');
$this->load->model(');
}
function index(){

$this->load->view('form_view.php');
/* $dta['name']=$this->input->post('name');
$dta['mail']=$this->input->post('email');
$dta['add']=$this->input->post('text');
$dta['ph']=$this->input->post(');

$this->form_model->insert($dta);*/

}
function insert_data()
{
$dta['name']=$this->input->post('name');
$dta['mail']=$this->input->post('email');
$dta['add']=$this->input->post('text');
$dta['ph']=$this->input->post(');
//print("<pre>");print_r($dta);die();
$this->form_model->insert($dta);
}

}
?&gt;
my model
&lt;?php
class Form_model extends Model
{
function Form_model()
{
parent::Model();
}
function insert($data)
{
//print("<pre>");print_r($data);die();
$data=Array('name' =>$data['name'],
'Email Id' => $data['mail'],
'address' => $data['add'],
'pn numb:'=> $data['ph']);
//print("<pre>");print_r($data);die();
$this->db->insert('abc', $data);

}
}
?&gt;
my view:
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Strict//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-strict.dtd">
&lt;html&gt;
&lt;head&gt;
&lt;meta http-equiv="content-type" content="text/html; charset=utf-8" /&gt;
&lt;title&gt;Godbit Code Igniter Tutorial: Creating a simple Registration Form&lt;/title&gt;
&lt;style type="text/css"&gt;
body {
font: small/1.5em Verdana, Arial, Helvetica, serif;
}
&lt;/style&gt;
&lt;/head&gt;
&lt;body&gt;
&lt;form action="form/insert_data" method="post"&gt;
<h1>Registration Form</h1>
<p>Please complete the following form:</p>
<table>
<tr><td>Name</td><td>&lt;input type="text" name="name" /&gt;&lt;/td></tr><br/>
<tr><td>Email id</td><td>&lt;input type="text" name="email" /&gt;&lt;/td></tr>
<tr><td>Address</td><td>&lt;textarea name="text" rows="10" cols="5"&gt;&lt;/textarea></td></tr>
<tr><td>Ph no:</td><td>&lt;input type="text" name="phnum"/&gt;&lt;/td></tr>
<tr><td>&lt;input type="submit" value="Submit"/&gt;&lt;/td></tr>
</table>
&lt;/form&gt;
&lt;/body&gt;
&lt;/html&gt;
error occuring is like this:
Fatal error: Call to a member function insert() on a non-object in C:\xampp\htdocs\CodeIgniter_1.7.3\system\application\models\form_model.php on line 16
pls help me I'm new in codeigniter and php.
#2

[eluser]Siddhesh[/eluser]
Hi nivi,

You must load the model where function "insert" exist.

Use $this->load->model("Form_model"); instead $this->load->model(’);

Hope this will help you.




Theme © iAndrew 2016 - Forum software by © MyBB