Can't update my Database using Codeigniter - php

I've just started to learning about CodeIgniter. But I stuck some point. After 7+ hours work and googling I decided to ask here. I am trying to update the database but I couldn't get out of it. After I enter data my data don't update. Here's my code ;
Takvim_Model.php
function __construct() {
parent::__construct();
}
public function insert($data) {
if ($this->db->insert('takvim', $data)) {
return true;
}
}
public function delete($roll_no) {
if ($this->db->delete('takvim', 'roll_no = '.$roll_no)) {
return true;
}
}
public function update($data,$old_roll_no) {
$this->db->set($data);
$this->db->where('roll_no', $old_roll_no);
$this->db->update('takvim', $data);
}
}
?>
Takvim_View.php
<!DOCTYPE html> <html lang = "en"> <head>
<meta charset = "utf-8">
<title>Takvim Example</title> </head> <body>
Add
<table border = "1">
<?php
$i = 1;
echo "<tr>";
echo "<td>Sr#</td>";
echo "<td>Roll No.</td>";
echo "<td>Name</td>";
echo "<td>Start Time</td>";
echo "<td>Stop Time</td>";
echo "<td>Update</td>";
echo "<td>Delete</td>";
echo "<tr>";
foreach($records as $r) {
echo "<tr>";
echo "<td>".$i++."</td>";
echo "<td>".$r->roll_no."</td>";
echo "<td>".$r->name."</td>";
echo "<td>".$r->start_time."</td>";
echo "<td>".$r->stop_time."</td>";
echo "<td><a href = '".base_url()."index.php/takvim/update/"
.$r->roll_no."'>Update</a></td>";
echo "<td><a href = '".base_url()."index.php/takvim/delete/"
.$r->roll_no."'>Delete</a></td>";
echo "<tr>";
}
?>
</table>
Takvim_Controller.php
<?php
class Takvim_controller extends CI_Controller {
function __construct() {
parent::__construct();
$this->load->helper('url');
$this->load->database();
}
public function index() {
$query = $this->db->get("takvim");
$data['records'] = $query->result();
$this->load->helper('url');
$this->load->view('Takvim_view', $data);
}
public function add_event_view() {
$this->load->helper('form');
$this->load->view('Takvim_add');
}
public function add_event() {
$this->load->model('Takvim_model');
$data = array (
'roll_no' => $this->input->post('roll_no'),
'name' => $this->input->post('name'),
'start_time' => $this->input->post('start_time')
);
$this->Takvim_model->insert($data);
$query = $this->db->get("takvim");
$data['records'] = $query->result();
$this->load->view('Takvim_view',$data);
}
public function update_event_view() {
$this->load->helper('form');
$roll_no = $this->uri->segment('3');
$query = $this->db->get_where("takvim",array("roll_no"=>$roll_no));
$data['records'] = $query->result();
$data = array('records' => $data['records']);
$this->load->view('Takvim_update',$data);
}
public function update_event(){
$this->load->model('Takvim_Model');
$data = array (
'roll_no' => $this->input->post('roll_no'),
'name' => $this->input->post('name'),
'start_time' => $this->input->post('start_time'),
'stop_time' => $this->input->post('stop_time')
);
$old_roll_no = $this->input->post('old_roll_no');
$this->Takvim_Model->update($data,$old_roll_no);
$query = $this->db->get("takvim");
$data['records'] = $query->result();
$this->load->view('Takvim_view',$data);
}
public function delete_event() {
$this->load->model('Takvim_Model');
$roll_no = $this->uri->segment('3');
$this->Takvim_Model->delete($roll_no);
$query = $this->db->get("takvim");
$data['records'] = $query->result();
$this->load->view('Takvim_view',$data);
}
} ?>
Takvim_Update.php
<!DOCTYPE html><html lang = "en"> <head> <meta charset = "utf-8">
<title>Takvim Example</title> </head> <body>
<form method = "" action = "">
<?php
echo form_open('Takvim_controller/update');
echo form_hidden('old_roll_no',$records[0]->roll_no);
echo form_label('Roll No.');
echo form_input(array('id'=>'roll_no',
'name'=>'roll_no','value'=>$records[0]->roll_no));
echo "
";
echo form_label('Name');
echo form_input(array('id'=>'name','name'=>'name',
'value'=>$records[0]->name));
echo "
";
echo form_label('Start Time');
echo form_input(array('id'=>'name','name'=>'name',
'value'=>$records[0]->start_time));
echo "
";
echo form_label('Stop Time');
echo form_input(array('id'=>'name','name'=>'name',
'value'=>$records[0]->stop_time));
echo "
";
echo form_submit(array('id'=>'submit','value'=>'Edit'));
echo form_close();
?>
</form>
Routes.php
$route['takvim'] = "Takvim_controller";
$route['takvim/add'] = 'Takvim_controller/add_event';
$route['takvim/add_view'] = 'Takvim_controller/add_event_view';
$route['takvim/update/(\d+)'] = 'Takvim_controller/update_event_view/$1';
$route['takvim/delete/(\d+)'] = 'Takvim_controller/delete_event/$1';

The name of model is not recomanded for Codeigniter
When you name a model use _model not _Model (This create conflit in your code)

In Takvim_Update.php you are submitting the form to 'Takvim_controller/update' and I can't see the update method in your Takvim_controller or the Takvim_controller/update route in your routes.php file.
First edit your Routes.php and add new route to your update method in Takvim_controller.
$route['takvim/update'] = 'Takvim_controller/update_event';
Then in Takvim_Update.php file submit your from to takvim/update url.
echo form_open('takvim/update');

try this:i hope it will help.
define routes.
$route['takvim/update/(:any)'] = 'Takvim_controller/update_event_view/$1';
//controller
first get data from table.and then update by whatever paramete's you want to update. for example i am giving primary key id of table.
$data=array(
'roll_no' => $this->input->post('roll_no'),
'name' => $this->input->post('name'),
'start_time' => $this->input->post('start_time'),
'stop_time' => $this->input->post('stop_time')
);
$this->Takvim_Model->update($id);
//model
function update($id){
return $this->db->where('id',$id)->update('table_name',$data);
}

Related

Array to string conversion on CodeIgniter

my problem is a want to insert multiple check box on my web application.
error Message
Array to string conversion
please help....
Controller :
public function add_overview_product($type)
{
if ($this->input->post('submit')) {
$type = $type;
$id_overview = $this->input->post('id_overview');
$records = array();
for ($i=0; $i < count($id_overview) ; $i++) {
$records[] = array(
'type' => $type,
'id_overview' => $id_overview[$i]
);
}
$check_idoverview = $this->Biostar->check_idoverview($type,$id_overview);
if ($check_idoverview > 0) {
$message = 'Sorry, The Product can not input twice with the same "TYPE" ';
} else {
foreach ($records as $key => $value) {
$datafield = array(
'type' => $type,
'id_overview' => $id_overview
);
$this->Biostar->saveoverviewproduct($datafield);
}
$data['type'] = $type;
$data['content'] = 'biostar/add_specification';
$this->load->view('dashboard/index', $data);
}
}
$data['diy'] = $diy;
$data['content'] = 'biostar/add_overview_product';
$this->load->view('dashboard/index', $data);
}
My : Model
public function saveoverviewproduct($datafield){
$sql = $this->db->insert('overview_biostar',$datafield);
return $sql;
}
public function check_idoverview($type,$id_overview){
$this->db->select('type');
$this->db->where('type',$type);
$this->db->where('id_overview',$id_overview);
$query = $this->db->get('overview_biostar')->rows();
return $query;
}
View:
<form method="post"action="<?php echo base_url(); ?>biostar/add_overview_product/<?php echo $type; ?>" >
<div class="box-body">
<?php foreach ($audio as $row){ ?>
<div class="checkbox">
<label>
<input type="checkbox" name="id_overview[]" value="<?php echo $row['title']; ?>"><?php echo $row['title']; ?>
</label>
</div>
<?php } ?>
</div>
$check_idoverview = $this->Biostar->check_idoverview($type,$id_overview);
$id_overview is an array. It should be a string.

Codeigniter Hidden Form Becomes NULL

I've got a really weird issue that I can't seem to figure out or understand. So essentially I have a to grab the ID passed through the Codeigniter URI, have it populate a hidden form, and then submitted. However when I submit the form as hidden, it comes back saying the data is NULL. I have tried and changed it to form_input and it works fine. Can anyone help me or explain to me why this is the case?
I have tried the following solutions.
URL
http://localhost/list/players/add/1/
where I want URI 3 ('1') to pass on to the form and submitted.
Solution 1 - Having the URI pass straight to data array
Controller
function add() {
if($this->form_validation->run() == FALSE) {
$data['view_file'] = 'add';
$this->load->module('template');
$this->template->cmslayout($data);
} else {
$league_id = $this->uri->segment(3);
$data = array(
'leagues_id' => $league_id,
);
if($this->_insert($data)){
return $query;
}
redirect ('/players/');
}
}
Solution 2 - Grabbing the URI and fill a hidden form
Controller
function add() {
$league_id = $this->uri->segment(3);
$this->load->module('leagues');
$data['leagues_list'] = $this->leagues->get_where($league_id);
if($this->form_validation->run() == FALSE) {
$data['view_file'] = 'add';
$this->load->module('template');
$this->template->cmslayout($data);
} else {
$data = array(
'leagues_id' => $this->input->post('leagues_id'),
);
if($this->_insert($data)){
return $query;
}
redirect ('/players/');
}
}
View
<?php
echo form_open('players/add/');
?>
<?php
echo "<br>";
echo "<br>";
echo "League Name";
echo "<br>";
foreach ($leagues_list->result() as $row) {
$league_id = $row->id;
$league_name = $row->league_name;
echo $league_name;
$data = array( 'name' => 'leagues_id',
'value' => $league_id,
);
echo form_hidden($data);
}
echo "<br>";
echo "<br>";
$data = array( 'value' => 'Set Player',
'name' => 'submit',
'class' => 'submit-btn',
);
echo form_submit($data);
echo form_close();
?>
In both scenarios, on submit it comes back with an error saying leagues_id is NULL. Now I have tried in Solution 2 to change from 'form_hidden' to 'form_input' and straight away clicking submit and it works fine.
Can anyone help me or advise why this is the case?
Many thanks.
If you want to add a parameter to your controller's function, you have to add it to: function func($parameter = 0) (= 0 is optional for default value).
In this case you can access the parameter by $parameter.
In your View file, you can open your form to post to the current url. For this you need to load the url helper in your controller: $this->load->helper('url'); (or you can autoload it in application/autoload.php).
Your form_hidden declaration was bad too. If you want to declare it with array(), then you have to use this syntax:
$data = array(
'name' => 'John Doe',
'email' => 'john#example.com'
);
echo form_hidden($data);
// Would produce:
<input type="hidden" name="name" value="John Doe" />
<input type="hidden" name="email" value="john#example.com" />
More information on Form helper: https://ellislab.com/codeigniter/user-guide/helpers/form_helper.html
For the right solution, try this:
Controller
function add($league_id = 0)
{
if($league_id != 0)
{
$this->load->module('leagues');
$data['leagues_list'] = $this->leagues->get_where($league_id);
if($this->form_validation->run() == FALSE)
{
$data['view_file'] = 'add';
$this->load->module('template');
$this->template->cmslayout($data);
}
else
{
$data = array(
'leagues_id' => $this->input->post('leagues_id'),
);
if($this->_insert($data))
{
return $query;
}
redirect ('/players/');
}
}
View
<?php
echo form_open(current_url());
echo "<br /><br />";
echo "League Name <br />";
foreach ($leagues_list->result() as $row)
{
$league_id = $row->id;
$league_name = $row->league_name;
echo $league_name;
echo form_hidden('leagues_id', $league_id);
}
echo "<br /><br />";
$data = array(
'value' => 'Set Player',
'name' => 'submit',
'class' => 'submit-btn'
);
echo form_submit($data);
echo form_close();
?>

Can't send correct data with view in codeIgniter

I'm trying to build a easy booking system in codeIgniter and using a database with a table called conference_rooms. I'm calling for this in my Booking_Model.phplike this:
public function __construct()
{
$this->load->database();
}
public function get_room() {
$query = $this->db->get('conference_rooms');
return $query->result_array();
}
}
To display it I'm using my Booking.php class looking like this:
public function view()
{
$data['conference_rooms'] = $this->booking_model->get_room();
if (empty($data['conference_rooms'])) {
show_404();
}
$data['title'] = $data['conference_rooms']['title'];
$this->load->view('templates/header', $data);
$this->load->view('view', $data);
$this->load->view('templates/footer');
}
And my view.php:
<h3><?php echo $conference_rooms['title']; ?></h3>
<div class="main">
<?php echo $conference_rooms['seats']; ?>
</div>
It won't find $room. What am I doing wrong?
UPDATE:
Basically changed the whole code, my view class now looks like this (changed to index in my Booking controller)
public function index() {
$this->load->helper('form');
$this->load->view('bootstrap/header');
$this->load->model('Booking_Model');
$rooms = $this->Booking_Model->get();
$rooms_form_options = array();
foreach ($rooms as $id => $room) {
$rooms_form_options[$id] = $room->title;
}
$this->load->model('Package_Model');
$packages = $this->Package_Model->get();
$packages_form_options = array();
foreach ($packages as $id => $package) {
$packages_form_options[$id] = $package->package_name;
}
$this->load->view('booking', array(
'rooms_form_options' => $rooms_form_options,
'packages_form_options' => $packages_form_options,
));
$this->load->view('bootstrap/footer');
}
And my booking.php;
<div>
<?php echo form_label('Conference Room', 'id') ; ?>
<?php echo form_dropdown('id', $rooms_form_options, set_value('id')); ?>
</div>
<div>
<?php echo form_label('Package type', 'package_id') ; ?>
<?php echo form_dropdown('package_id', $packages_form_options, set_value('package_id')); ?>
</div>
<div>
<?php echo form_label('Antal deltagare', 'number_people') ; ?>
<?php echo form_input('number_people', set_value('number_people')) ; ?>
</div>
<div>
<?php echo form_submit('preview', 'Book'); ?>
</div>
Use this
In Model
<?
function __construct()
{
$this->load->database();
}
function get_room() {
$query = $this->db->get('conference_rooms');
$result = $query->result_array();
return $result;
}
?>
In controller
function view()
{
$data['conference_rooms'] = $this->booking_model->get_room();
if (empty($data['conference_rooms']))
{
show_404();
}
else
{
$this->load->view('templates/header', $data);
$this->load->view('view', $data);
$this->load->view('templates/footer');
}
}
?>
in view
<h3><?php echo $conference_rooms[0]['title']; ?></h3>
<div class="main">
<?php echo $conference_rooms[0]['seats']; ?>
</div>
cz of $conference_rooms[0] pointing 0 is we passing data with Objective array. so we need to point data. check with print_r
MODEL
You need to row_array(); to return an array
public function get_room() {
$query = $this->db->get('conference_rooms');
$rowcount = $query->num_rows();
if( $rowcount > 0 ){
return $row = $query->row_array();
} else {
return FALSE;
}
}
CONTROLLER
public function view()
{
$conference_rooms = $this->booking_model->get_room();// asing your array to variable
if (empty($conference_rooms)) {
show_404();
} else {
$data['conference_rooms']=$conference_rooms;// pass your variable to data array to pass into view
$this->load->view('templates/header', $data);
$this->load->view('view', $data);
$this->load->view('templates/footer');
}
}
VIEW
<h3><?php echo $conference_rooms['title']; ?></h3>
<div class="main">
<?php echo $conference_rooms['seats']; ?>
</div>

read more function with codeigniter

i am trying to create a readmore function in codeigniter where the readmore link will be linked to a controller which would show all the data about that particular id....i am kind of confused on how to go about it... i tried...
<?php
$research_detail_url = site_url()."/research/research_details";
//echo json_encode($research)
if($research)
{
foreach ($research as $_research) {
$author = $_research->author;
$content = $_research->content;
$dsubmitted = $_research->dsubmitted;
echo "<div class='menu-collapse'> <h5>$author</h5>";
echo "<p>";
echo "<span class='support_text'>$content <span><br />";
echo "<span class='support_text'>$dsubmitted <span><br />";
echo "<a href='$research_detail_url' target='_blank' style='text-decoration:underline; color:#0088cc;'>
read more ยป </a>";
echo "</p> </div>";
}
}
?>
but i seem not be getting any results...i need help...
and this is my controller function.....
public function research_details($id='')
{
if(!$id)
{
echo "Project Id required";
return;
}
$_result = $this->projects_model->get_project($id);
if($_result)
{// success in fetching data hurray
$result['projects'] = $_result;
$users_ids = $this->users_model->get_user_ids(); //return available user id's
$groups_ids = $this->groups_model->get_group_ids(); //return available group id's
//echo json_encode($users_ids);
//echo json_encode($groups_ids);
$group_record = $this->map_names_to_ids($users_ids , $groups_ids );
$result['group_record'] = $group_record;
//load the view
$this->load->view('__includes__/header');
$this->load->view('__includes__/boostrap_responsive');
$this->load->view('projects/project_panel', $result);
$this->load->view('__includes__/footer_scripts');
$this->load->view('__includes__/wijmo_file_jquery');
$this->load->view('__includes__/footer');
}
else
{
exit("An Error occured in fetching the requested project");
}
}
and this is my model.....
<?php
class research_model extends CI_Model {
function add()
{
$this->db->insert('research',$_POST);
if($this->db->_error_number())
{
return $this->db->_error_number();
}
}
function update($article_id, $data_fields = NULL){
if($data_fields == NULL)
{
$this->db->where("article_id =".$article_id);
$this->db->update('research',$_POST);
}
else
{
$this->db->where("article_id =".$article_id);
$this->db->update('research',$data_fields);
}
$is_error = $this->db->_error_number();
if($is_error){
echo $is_error;
}
return TRUE;
}
function delete($id){
$this->db->where("article_id =".$id);
return $this->db->delete('research');
}
//return the research with this id
function get_research($id){
$this->db->where("article_id =".$id);
$query = $this->db->get('research');
if ($query->num_rows() > 0){
return $query->row_array();
}
else
echo $this->db->_error_message();
return FALSE;
}
//return the available research in the table
function get_research_all(){
$query = $this->db->get('research');
if ($query->num_rows() > 0)
{
foreach($query->result() as $row)
{
$result[] = $row;
}
return $result;
}
}
}
and my entire controller.....
<?php
class Research extends Public_Controller
{
function __construct()
{
parent::__construct();
$this->load->model('research_model');
}
function index()
{
if($this->ion_auth->is_admin())
{
$result = $this->research_model->get_research_all();
$data = array(
'main_content' => 'research/index',
'research' => $result
);
$this->load->view("loader", $data);
}
else
{
redirect('home');
}
}//END INDEX
// public view
function current()
{
$result = $this->research_model->get_research_all();
$data = array('research' => $result);
$this->load->view('__includes__/header');
$this->load->view('__includes__/navbar');
$this->load->view('research/current', $data);
$this->load->view('__includes__/footer');
}
function add()
{
if($this->ion_auth->is_admin())
{
$this->load->view("loader",array('main_content'=>"research/add_research"));
}
}//END ADD
function edit($id='')
{
if(! $id)
{
echo "research Id required";
return;
}
$result = $this->research_model->get_research($id);
if( ! $result)
{
echo "Nothing to edit";
return;
}
$result['main_content'] = "research/add_research";
$this->load->view("loader",$result);
}//END EDIT
function delete($id='')
{
if(! $id)
{
echo "Id required";
return;
}
$this->research_model->delete($id);
$this->get_research();
}//END DELETE
function submit($id='')
{
//validate form [perform validation server-side to make sure of fields]
$this->load->library('form_validation');
$this->form_validation->set_rules('author', 'Author', 'trim|required|min_length[4]');
if ($this->form_validation->run() == FALSE){
//ajax data array
$data = array(
'server_validation' => validation_errors()
);
echo str_replace('\\/', '/', json_encode($data));
}
else{
if($id){
$result = $this->research_model->update($id);
$content = "article has been UPDATED successfully";
//$retArr["content"] = $content;
//echo json_encode($retArr);
}
else{
$result = $this->research_model->add();
$content = "article has been CREATED successfully";
//$retArr["content"] = $content;
//echo json_encode($retArr);
}
//if duplicate key
if($result == 1062){
//ajax data array
$data = array();
$data['is_valid'] = 0;
echo json_encode($data);
}else{
//ajax data array
$data = array(
'is_valid' => 1,
'content' => $content
);
echo json_encode($data);
}
}//end ELSE form valid
}//END SUBMIT
public function research_details($id='')
{
if(!$id)
{
echo "Project Id required";
return;
}
$_result = $this->research_model->get_research($id);
if($_result)
{// success in fetching data hurray
$result['article'] = $_result;
//load the view
$this->load->view('__includes__/header');
$this->load->view('__includes__/boostrap_responsive');
$this->load->view('research/research_details', $Aresult);
$this->load->view('__includes__/footer_scripts');
$this->load->view('__includes__/wijmo_file_jquery');
$this->load->view('__includes__/footer');
}
else
{
exit("An Error occured in fetching the requested project");
}
}//END EDIT
}
?>
my public controller
<?php
abstract class Public_Controller extends CI_Controller
{
public $about_data;
function __construct()
{
parent::__construct();
//Making This variable availale for the whole site
$this->load->model('about_model');
$this->load->model('captcha_model');
//get your data
$this->about_data = $this->about_model->get_abouts();
}
}
?>
I see a couple of problems:
In your view, you are not closing the span tags. You need
</span>
In your view, you are creating the link, but you are not
including an ID, which you need in your controller. What I mean by this is the following:
First,you create this $research_detail_url = site_url()."/research/research_details";.
Then echo "<a href='$research_detail_url' target='_blank' style=''>read more</a>";
As you can see, your URL does not have an ID when created. What you should do is something like this: $research_detail_url = site_url()."/research/research_details/31"; where 31 is a random ID. You need to come up with the right ID needed in order to pass it to your controller. Your controller is currently assigning a blank ID since none is being passed which is why you end up with a result of "Project Id required"

PHP Update in codeigniter

I am trying to write a function to insert, update, and delete data. I can insert data, but can't update the data. The problem is I can't pass id value to my updateform.
Controller:
function update($id = 0){
$this->load->helper('form');
$this->load->helper('html');
$this->load->model('employees_model');
if($this->input->post('upsubmit')){
echo '<pre>';print_r($id);echo '</pre>';
exit();
if($this->input->post('eid')){
$this->employees_model->entry_update();
}
}
$data = $this->employees_model->general();
if((int)$id > 0){
$query =this->employees_model->get($id);
$data['txt_id']['value'] = $query['eid'];
$data['txt_name']['value'] = $query['ename'];
$data['txt_salary']['value'] = $query['esalary'];
$data['txt_emailid']['value'] = $query['eemailid'];
}
$this->load->view('employees_update',$data);
}
Model:
function general(){
$data['base'] = $this->config->item('base_url');
$data['css'] = $this->config->item('css');
$data['id']['value'] = 'eid';
$data['name'] = 'txt_name';
$data['salary'] = 'txt_salary';
$data['emailId'] = 'txt_email';
return $data;
}
function entry_update($id){
$this->load->database();
echo '<pre>';print_r($id);echo '</pre>';
exit();
$data = array(
'ename'=>$this->input->post('txt_name'),
'esalary'=>$this->input->post('txt_salary'),
'eemailid'=>$this->input->post('txt_email'),
);
echo '<pre>';print_r($data);echo '</pre>';
exit();
$this->db->where('eid',$this->input->post($data));
$this->db->update('employee',$data);
//echo '<pre>';print_r($data);echo '</pre>';
echo "Updated successfully";
}
function get($id)
{
$this->load->database();
$query = $this->db->get_where('employee',array('eid'=>$id));
return $query->row_array();
}
Please suggest how to pass Select id values to update form page in views section.
Here is my working sample code. Hopes it helps.
controller
//I am using update from to preload data
function update_form($id)
{
$query=$this->product_model->get($id);
$data['id']=$query['id'];
$data['name']=$query['name'];
$data['price']=$query['price'];
$this->load->view('products/update_product',$data);
}
function update()
{
$this->product_model->save();
redirect('products/index');
}
Model
function get($id=0)
{
if($id==0)
{
$query=$this->db->get('product');
return $query->result_array();
}
else
{
$this->db->where('id',$id);
$query=$this->db->get('product');
return $query->row_array();
}
}
// if **id** is greater than zero mean update, no **id** mean insert
function save()
{
$id=$this->input->post('id');
$name=$this->input->post('name');
$price=$this->input->post('price');
$data=array
(
'name'=>$name,
'price'=>$price
);
if($id>0)
{
$this->db->where('id',$id);
$this->db->update('product',$data);
}
else
{
$this->db->insert('product',$data);
}
}
}
View (view/products/update_product.php)
<?php echo form_open('products/save');?> //form_open('controller_name/function_name');
<?php echo form_hidden('id',$id);?>
<?php echo form_input('name',$name,'placeholder="enter doctor name"');?><br>
<?php echo form_input('price',$pricce,'placeholder="enter doctor phone number"');?><br>
<?php echo form_submit('','Update');?>
<?php echo form_close();?>
id play vita role in updating , you shouldn't include it in View as Hidden Field
At first you created function with parameter $id. But when you call the function without parameter.
change this line
in Controller change this line
$this->employees_model->entry_update();
to
$this->employees_model->entry_update($this->input->post('eid'));
In Model Change this line:
$this->db->where('eid',$this->input->post($data))
to
$this->db->where('eid',$this->input->post('eid'));
Change your update function like as below:
function update($id = 0){
$this->load->helper('form');
$this->load->helper('html');
$this->load->model('employees_model');
if($this->input->post('upsubmit')){
$id= $this->input->post('eid');
if($this->input->post('eid')){
$this->employees_model->entry_update();
}
}
$data = $this->employees_model->general();
if((int)$id > 0){
$query =this->employees_model->get($id);
$data['txt_id']['value'] = $query['eid'];
$data['txt_name']['value'] = $query['ename'];
$data['txt_salary']['value'] = $query['esalary'];
$data['txt_emailid']['value'] = $query['eemailid'];
}
$this->load->view('employees_update',$data);
}

Categories