Articles → PHP CODEIGNITER → Insert Method In The Active Records In Codeigniter

Insert Method In The Active Records In Codeigniter






Table




Picture showing the schema of the agent table

Click to Enlarge


User Interface




Picture showing the user interface of create agent

Click to Enlarge


Code To Insert Data In The Table




if(!empty($_REQUEST))
{
$agent = array(
"agent_name" => $this->input->post("agentname"),
"contact_number" => $this->input->post("contactnumber"),
"email_id"=> $this->input->post("emailid"),
"state"=> $this->input->post("state"),
"city"=> $this->input->post("city"),
"agent_address"=> $this->input->post("address"),
"pin_code"=> $this->input->post("pin")
);
$this->load->model('AgentModel');
$this->AgentModel->InsertAgent($agent);
}






public function InsertAgent($agent)
{
$this->load->database(); 
$this->db->insert("Agents", $agent);
}



Output


Picture showing the data inserted in the agent table

Click to Enlarge


Posted By  -  Karan Gupta
 
Posted On  -  Sunday, November 29, 2020

Query/Feedback


Your Email Id  
 
Subject 
 
Query/FeedbackCharacters remaining 250