SlideShare a Scribd company logo
Data Insert
View
<!DOCTYPE html>
<html>
<head>
<title>Registration form</title>
</head>
<body>
<form method="POST" action="<?php echo URL; ?>index.php/Crud/savedata">
<table width="600" border="1" cellspacing="5" cellpadding="5">
<tr>
<td width="230">Sap_id </td>
<td width="329"><input type="text" value="" name="sap_id"/></td>
</tr>
<tr>
<td>Name </td>
<td><input type="text" value="" name="name"/></td>
</tr>
<tr>
View
<td>Email ID </td>
<td><input type="email" value="" name="email"/></td>
</tr>
<tr>
<td>Address</td>
<td><input type="text" name="address"/></td>
</tr>
<tr>
<td colspan="2" align="center"><input type="submit" name="save" value="Save Data"/></td>
</tr>
</table>
</form>
</body>
</html>
Build DB Connection
Application folder->config folder->database file
Model
<?php
class Crud_model extends CI_Model
{
function saverecords($data)
{
$this->db->insert('student',$data);
return true;
}
}
Controller
<?php
class Crud extends CI_Controller
{
public function __construct()
{
/*call CodeIgniter's default Constructor*/
parent::__construct();
$this->load->helper('url');
/*load database libray manually*/
$this->load->database();
/*load Model*/
$this->load->model('Crud_model');
}
Controller….
/*Insert*/
public function index(){
$this->load->view('insert');
}
public function savedata()
{
$data=array();
/*load registration view form*/
/*Check submit button */
if($this->input->post('save'))
{
Controller…..
$data['sap_id']=$this->input->post('sap_id');
$data['name']=$this->input->post('name');
$data['email']=$this->input->post('email');
$data['address']=$this->input->post('address');
$response=$this->Crud_model->saverecords($data);
if($response==true){
echo "Records Saved Successfully";
}
else{
echo "Insert error !";
}
}
header("Location:".URL);
}
}
?>
Data Fetch and Display using Code igniter
Model(Crud_model.php)
<?php
class Crud_model extends CI_Model
{
/*View*/
function display_records()
{
$query=$this->db->get("crud");
return $query->result();
}
}
Controller(Crud.php)
<?php
class Crud extends CI_Controller
{
public function __construct()
{
/*call CodeIgniter's default Constructor*/
parent::__construct();
/*load database libray manually*/
$this->load->database();
/*load Model*/
$this->load->model('Crud_model');
}
Controller(Crud.php)con..
/*Display*/
public function displaydata()
{
$result['data']=$this->Crud_model->display_records();
$this->load->view('display_records',$result);
}
}
?>
View(display_records.php)
<html>
<head>
<title>Display records</title>
<style>
table, th, td {
border: 1px solid black;
border-collapse: collapse;
}
</style>
</head>
<body>
<table width="600" border="0" cellspacing="5" cellpadding="5">
<tr style="background:#CCC">
<th>Sr No</th>
<th>First_name</th>
<th>Last_name</th>
<th>Email Id</th>
</tr>
View(display_records.php)con..
<?php
$i=1;
foreach($data as $row)
{
echo "<tr>";
echo "<td>".$i."</td>";
echo "<td>".$row->first_name."</td>";
echo "<td>".$row->last_name."</td>";
echo "<td>".$row->email."</td>";
echo "</tr>";
$i++;
}
?>
</table>
</body>
</html>
Run Operation
For server loading file URL for data fetch
http://localhost/codeIgniter/index.php/Crud/displaydata
• “Crud” is a backend file that exist is controller
• “displaydata” is a public function in backend file that exist is controller that use for data display using curd
and view file
data insert in codeigniter.pptx
Crud_model
<?php
class Crud_model extends CI_Model
{
/*Display*/
function display_records()
{
$query=$this->db->query("select * from student");
return $query->result();
}
function displayrecordsById($id)
{
$query=$this->db->query("select * from form where id='".$id.”’”);
return $query->result();
}
Crud_model..
/*Update*/
function
update_records($sap_id,$name,$email,$cell_no,$address)
{
$query=$this->db->query("update form SET sap_id='$sap_id'
name='$name',email='$email',cell_no='$cell_no,address='$address'
where id='$id’”);
}
}
Crud
<?php
class Crud extends CI_Controller
{
public function __construct()
{
/*call CodeIgniter's default Constructor*/
parent::__construct();
/*load database libray manually*/
$this->load->database();
/*load Model*/
$this->load->model('Crud_model');
}
Crud..
public function dispdata()
{
$result['data']=$this->Hello_model->display_records();
$this->load->view('display_records',$result);
}
public function updatedata()
{
$id=$this->input->get('id');
$result['data']=$this->Crud_model->displayrecordsById($id);
$this->load->view('update_records',$result);
Crud…
if($this->input->post('update'))
{
$name=$this->input->post('sap_id');
$name=$this->input->post('name');
$email=$this->input->post('email');
$cell_no=$this->input->post('cell_no');
$address=$this->input->post('address');
$this->Crud_model->update_records($first_name,$last_name,$email,$id);
Echo”update sucessfully”
}
}
}
?>
Display record
echo "<td><a href=‘updatedata?id=".$row->id."'>Update</a></td>";
Update Record
<?php
$i=1;
foreach($data as $row)
{
?>
------------------------------------------------------------------------------------------
<td width="230">Enter SAP_ID </td>
<td width="329"><input type="text" name="sap_id" value="<?php echo
$row->sap_id; ?>"/></td>
----------------------------------------------------------------------------------------------
<input type="submit" name="update" value="Update_Records"/></td>

More Related Content

PPTX
Sessionex1
PPTX
Java script form validation
PDF
Practicals it
PPTX
Lect# 1 html part ii
DOCX
12th Computer practical pattern (sci & com both)
DOC
Form & frame
PDF
Update statement in PHP
DOCX
sri_ITSD325_IP3Code-ShoppingAbout UsfrmAboutus.aspx@ Page.docx
Sessionex1
Java script form validation
Practicals it
Lect# 1 html part ii
12th Computer practical pattern (sci & com both)
Form & frame
Update statement in PHP
sri_ITSD325_IP3Code-ShoppingAbout UsfrmAboutus.aspx@ Page.docx

Similar to data insert in codeigniter.pptx (20)

PDF
Webpro2 pert6 7_login_menu_
PDF
Creating web api and consuming part 2
PDF
Skills development: HTML Code
PPTX
13. view data
PDF
vue-components.pdf
PPTX
14. add data in symfony4
PDF
krish (1).pdf
DOC
Ex[1].3 php db connectivity
PPSX
Lecture-5.ppsx
PDF
The HyperText Markup Language or HTML is the standard markup language
PPTX
INTRODUCTION TO HTML & CSS .pptx
PDF
Creating simple php contact form
PPTX
Workshop on Web designing by GDG on campus: IIMT, Meerut
PDF
Html server control - ASP. NET with c#
TXT
PPTX
SQL2.pptx from vu university short and long
PDF
JS1.pdf
PDF
DOCX
My project working well, but there no relationship between the t.docx
Webpro2 pert6 7_login_menu_
Creating web api and consuming part 2
Skills development: HTML Code
13. view data
vue-components.pdf
14. add data in symfony4
krish (1).pdf
Ex[1].3 php db connectivity
Lecture-5.ppsx
The HyperText Markup Language or HTML is the standard markup language
INTRODUCTION TO HTML & CSS .pptx
Creating simple php contact form
Workshop on Web designing by GDG on campus: IIMT, Meerut
Html server control - ASP. NET with c#
SQL2.pptx from vu university short and long
JS1.pdf
My project working well, but there no relationship between the t.docx
Ad

Recently uploaded (20)

PPTX
The Effect of Human Resource Management Practice on Organizational Performanc...
PPTX
Project and change Managment: short video sequences for IBA
PPTX
Primary and secondary sources, and history
PPTX
Presentation for DGJV QMS (PQP)_12.03.2025.pptx
PPTX
INTERNATIONAL LABOUR ORAGNISATION PPT ON SOCIAL SCIENCE
PPTX
worship songs, in any order, compilation
PPTX
Sustainable Forest Management ..SFM.pptx
PPTX
Intro to ISO 9001 2015.pptx wareness raising
PDF
oil_refinery_presentation_v1 sllfmfls.pdf
DOC
学位双硕士UTAS毕业证,墨尔本理工学院毕业证留学硕士毕业证
PDF
Tunisia's Founding Father(s) Pitch-Deck 2022.pdf
PPTX
Relationship Management Presentation In Banking.pptx
PPTX
ART-APP-REPORT-FINctrwxsg f fuy L-na.pptx
PPTX
Tablets And Capsule Preformulation Of Paracetamol
PPTX
An Unlikely Response 08 10 2025.pptx
PDF
Presentation1 [Autosaved].pdf diagnosiss
PPTX
PHIL.-ASTRONOMY-AND-NAVIGATION of ..pptx
PPTX
AcademyNaturalLanguageProcessing-EN-ILT-M02-Introduction.pptx
PPTX
Impressionism_PostImpressionism_Presentation.pptx
PDF
Swiggy’s Playbook: UX, Logistics & Monetization
The Effect of Human Resource Management Practice on Organizational Performanc...
Project and change Managment: short video sequences for IBA
Primary and secondary sources, and history
Presentation for DGJV QMS (PQP)_12.03.2025.pptx
INTERNATIONAL LABOUR ORAGNISATION PPT ON SOCIAL SCIENCE
worship songs, in any order, compilation
Sustainable Forest Management ..SFM.pptx
Intro to ISO 9001 2015.pptx wareness raising
oil_refinery_presentation_v1 sllfmfls.pdf
学位双硕士UTAS毕业证,墨尔本理工学院毕业证留学硕士毕业证
Tunisia's Founding Father(s) Pitch-Deck 2022.pdf
Relationship Management Presentation In Banking.pptx
ART-APP-REPORT-FINctrwxsg f fuy L-na.pptx
Tablets And Capsule Preformulation Of Paracetamol
An Unlikely Response 08 10 2025.pptx
Presentation1 [Autosaved].pdf diagnosiss
PHIL.-ASTRONOMY-AND-NAVIGATION of ..pptx
AcademyNaturalLanguageProcessing-EN-ILT-M02-Introduction.pptx
Impressionism_PostImpressionism_Presentation.pptx
Swiggy’s Playbook: UX, Logistics & Monetization
Ad

data insert in codeigniter.pptx