I am using PHP MVC Framework and using data table to for create / Update and Delete
I am using PHP MVC Framework and using data table to for create / Update and Delete

Hello ,
I am using CodeIgniter framework and i have used dataTable to show a list and also create ,update and delete functionality .
I was going ok but now i am getting an error when creating a new data it's properly getting in database but showing in Modal (Something goes wrong ,Please Refresh Page and try agian !)
Here is my source code .
var editor; // use a global for the submit and return data rendering in the examples
$(document).ready(function() {
editor = new $.fn.dataTable.Editor( {
serverSide: true,
ajax: "<?php echo site_url(); ?>/user/crud",
table: "#example",
idSrc: "id",
fields: [ {
label: "Company Name:",
name: "Comapny_Name"
}, {
label: "Contact first name",
name: "first_name"
}, {
label: "Contact last name",
name: "last_name"
},{
label: "Contact Email Address ",
name: "email"
},{
label: "Contact Password ",
name: "password",
type: "password"
},{
label: "Date:",
name: "date",
type: "date",
def: function () { return new Date(); },
dateFormat: $.datepicker.ISO_8601
}
],
i18n: {
create: {
button: "Create",
title: "Create New ",
submit: "Submit"
},
edit: {
button: "Edit",
title: "Edit",
submit: "Submit"
},
remove: {
button: "Delete",
title: "Are you sure ",
submit: "Submit",
confirm: {
_: "Something goes wrong ,Please Refresh Page and try agian !",
1: "Are you sure you wish to delete 1 row?"
}
},
error: {
system: "Something goes wrong ,Please Refresh Page and try agian !";
}
}
} );
editor.on( 'preSubmit', function ( e, o, action ) {
if ( action !== 'remove' ) {
if ( o.data.Comapny_Name === '' ) {
this.error('Comapny_Name', 'A company name must be given');
return false;
}
else if ( o.data.first_name === '' ) {
this.error('first_name', 'A first name must be given');
return false;
}
else if ( o.data.first_name.length >= 10 ) {
this.error('first_name', 'The first name length must be less that 10 characters');
return false;
}
else if ( o.data.last_name === '' ) {
this.error('last_name', 'A lirst name must be given');
return false;
}
else if ( o.data.last_name.length >= 10 ) {
this.error('last_name', 'The lirst name length must be less that 10 characters');
return false;
}
else if ( o.data.email === '' ) {
this.error('email', 'A email must be given');
return false;
}
else if ( o.data.password === '' ) {
this.error('password', 'A password must be given');
return false;
}
else if ( o.data.password.length >= 6) {
this.error('password', 'The password length must be less that 6 characters');
return false;
}
// ... etc
}
} );
$('#example').DataTable( {
dom: "Tfrtip",
ajax: "<?php echo site_url(); ?>/user/crud",
columns: [
{ data: null, render: function ( data, type, row ) {
// Combine the first and last names into a single table field
return data.first_name+" "+data.last_name;
} },
{ data: "Comapny_Name" },
{ data: "date" }
],
tableTools: {
sRowSelect: "os",
aButtons: [
{ sExtends: "editor_create", editor: editor },
{ sExtends: "editor_edit", editor: editor },
{ sExtends: "editor_remove", editor: editor }
]
}
} );
} );
PHP Code
function crud(){
if(is_loogedin()) //Checking logged in or not from helper
{
//Create new
if($this->input->post("action")=="create"){
$postdata=$this->input->post("data");
$newdata=array(
"Comapny_Name"=>$postdata["Comapny_Name"],
"first_name"=>$postdata["first_name"],
"last_name"=>$postdata["last_name"],
"email"=>$postdata["email"],
"password"=>$postdata["password"],
"date"=>$postdata["date"]
);
if($this->user_model->insertnewcompany($newdata)){
$source=$this->user_model->getdata();
$data=array(
"data"=>$source,
"sessionId"=>$this->data['sessionId'],
"tenantName"=>$this->input->post("Comapny_Name"),
"NewInsert"=>"true",
);
}else{
$data=array(
"sessionId"=>$this->data['sessionId'],
"tenantName"=>"Null",
"NewInsert"=>"Fail"
);
}
echo json_encode($data);
}
//update
if($this->input->post("action")=="edit"){
$newdata=array(
"Comapny_Name"=>$this->input->post("Comapny_Name"),
"first_name"=>$this->input->post("first_name"),
"last_name"=>$this->input->post("last_name"),
"email"=>$this->input->post("email"),
"password"=>$this->input->post("password"),
"date"=>$this->input->post("date"),
"session_id"=>$this->data['sessionId']
);
if($this->user_model->updatenewcompany($newdata)){
$data=array(
"sessionId"=>$this->data['sessionId'],
"tenantName"=>$this->input->post("Comapny_Name"),
"Updated"=>"true"
);
}else{
$data=array(
"sessionId"=>$this->data['sessionId'],
"tenantName"=>"Null",
"Updated"=>"Fail"
);
}
echo json_encode($data);
}
//Delete
if($this->input->post("action")=="delete"){
$newdata=array(
"id"=>$this->input->post("id"),
);
if($this->user_model->deletecompany($newdata)){
$data=array(
"sessionId"=>$this->data['sessionId'],
"tenantName"=>$this->input->post("Comapny_Name"),
"Deleted"=>"true"
);
}else{
$data=array(
"sessionId"=>$this->data['sessionId'],
"tenantName"=>"Null",
"Deleted"=>"Fail"
);
}
echo json_encode($data);
}
//else
else{
$source=$this->user_model->getdata();
$data=array(
"data"=>$source,
);
echo json_encode($data);
}
}else{$this->load->view("login");}
}
Answers
I just solved it myself .Please change this to solved .
Thanks
this question may be a little too specific to get any help...if you turn on php error messages what does it say? or the browser console error log?