Update multiple checkbox in codeigniter - php
I'm new in codeigniter. I'm developing student Information project. There is one form with multiple check box that looks like this:
So first the inserted values are put inside the checkbox. The value is checked first but when I select another set of values, only the last value is updated.
I want to update multiple checkbox.
Thanks in advance.
MY Code
Controller:delete.php
<?php
class delete extends CI_Controller
{
function __construct()
{
parent::__construct();
$this->load->helper('url');
$this->load->helper('form');
$this->load->helper('html');
$this->load->model("delete_model");
$this->load->library("pagination");
//$this->load->library('table');
}
function GetAll()
{
$this->load->model('delete_model');
$data['query']=$this->delete_model->GetAll();
$this->load->view('studentview_view',$data);
}
//Get Record By Id
function getstudbyid($id)
{
$this->load->model("delete_model");
$data['student']=$this->delete_model->getstuddetailsbyid($id);
//echo $this->db->last_query();
$this->load->view("displayview",$data);
}
//pagination
function test($start_from = 1)
{
$this->load->model('delete_model');
$this->load->library('pagination');
// $data['query']=$this->delete_model->GetAll();
$data = array();
$per_page = 3;
$this->load->model('delete_model');
$total = $this->delete_model->record_count();
$start = $per_page * ($start_from-1);
$data['student'] = $this->delete_model->get($per_page, $start);
$config['base_url'] = base_url() . "index.php/delete/test";
$config['total_rows'] = $total;
$config['per_page'] = $per_page;
$config['uri_segment'] = 2;
$config['num_links'] = 2;
$config['use_page_numbers'] = TRUE;
//$config['overwrite'] = TRUE;
$this->pagination->initialize($config);
$data['pagination'] = $this->pagination->create_links();
foreach($data['student'] as $key=>$value){
//echo $key;
foreach($value as $k=>$v)
{
if ( $k == 'id') {
anchor('delete/del'.$v,'delete');
anchor('delete/input/'.$v,'Edit');
}
}}
// $data['table'] = $this->table->generate();
$this->load->view('studentlist' ,$data);
}
//Delete Record
function del($id){
$this->load->helper('html');
$this->load->model('delete_model');
if((int)$id > 0){
$this->delete_model->delete($id);
}
$data = $this->delete_model->delete();
$data['student'] = $this->delete_model->delete();
redirect($_SERVER['HTTP_REFERER']);
//$this->load->view('studentlist',$data);
}
//Update Record
function input($id=0)
{
$this->load->model('delete_model');
if($this->input->post('btnupdate'))
{
if($this->input->post('id'))
{
$this->delete_model->entry_update();
echo $this->db->last_query();
}
else
{
$this->student_model->student();
}
}
$data = $this->delete_model->student_data();
if((int)$id > 0)
{
$query = $this->delete_model->getstuddetailsbyid($id);
print_r($query);
//echo $this->db->last_query();
// $data['fid']['value'] = $query['id'];
// $data['up_std_name']['value'] =$query['std_name'];
// $data['up_std_address']['value']=$query['std_address'];
// $data['stud_class']['value']=$query['std_class'];
// $data['up_std_language']['value']=$query['std_language'];
$data['fid'] = $query['id'];
$data['up_std_name']=$query['std_name'];
$data['up_std_address']=$query['std_address'];
$data['stud_class']=$query['std_class'];
$data['up_std_language']=$query['std_language'];
$data['up_std_gender'] =$query['std_gender'];
echo "--------";
//print_r($data);
echo "----bhumika----";
//print_r($query['std_languag']);
print_r($data['up_std_language']);
echo "---a---";
echo "<br/>";
echo "<br/>";
// if($query['std_gender']=='F')
// {
// $data['up_std_gender']['checked'] = TRUE;
// }
// else
// {
// $data['up_std_gender']['checked'] = FALSE;
// }
// $data['up_std_birthdate']['value']=$query['std_birthdate'];
// $data['up_std_photo']['value']=$query['std_photo'];
// $data['up_std_ilanguage']['value']=$query['std_int_language'];
// print_r($data['up_std_ilanguage']['value']);
$data['up_std_birthdate']=$query['std_birthdate'];
$data['up_std_photo']=$query['std_photo'];
$data['up_std_ilanguage']=$query['std_int_language'];
// print_r($data['up_std_ilanguage']);
}
$this->load->view('finalview',$data);
}
}
?>
Model:delete_model.php
<?php
class delete_model extends CI_Model{
function stud_delete_model()
{
parent::CI_Model();
}
//View Record
public function GetAll()
{
$this->load->database();
$query=$this->db->get('student');
return $query->result();
}
//paging
public function record_count() {
$this->load->database();
$this->db->count_all("student");
// echo $this->db->last_query();
return $this->db->count_all("student");
}
function get($limit,$start_from)
{
$this->load->database();
$sql = "SELECT * FROM student LIMIT $start_from, $limit";
$query = $this->db->query($sql);
// echo $this->db->last_query();
return $query->result_array();
}
//view Record by id
public function getstuddetailsbyid($id)
{
$this->load->database();
$query=$this->db->get_where('student',array('id'=>$id));
//$this->db->last_query();
return $query->row_array();
}
//Delete Record
function delete($id)
{
$this->load->database();
$this->db->where('id',$id);
$this->db->delete('student');
}
//Update Record
function entry_update()
{
$this->load->database();
$date=$this->input->post('datepicker');
$data=array(
'std_name'=>$this->input->post('std_name1'),
'std_address'=>$this->input->post('std_address1'),
'std_class'=>$this->input->post('std_class'),
'std_language'=>$this->input->post('std_language1'),
'std_gender'=>$this->input->post('std_gender1'),
'std_birthdate'=>date('Y-m-d', strtotime(str_replace('-', '/', $date))),
'std_photo'=>$this->input->post('userfile'),
'std_int_language'=>$this->input->post('std_ilanguage1')
);
//$t=$this->input->post('std_language1');
// echo "***";
// echo $t;
//print_r($t);
// if(isset($this->input->post['std_language1']))
// {
// $q=implode(',',$this->input->post['std_language1'] );
// echo "(((((";
// print_r($q);
//$data['q']=$q;
//print_r($data);
// }
// else
// {
// $q='';
// }
// echo $q;
print_r($data);
$this->db->where('id',$this->input->post('id'));
$this->db->update('student',$data);
}
function student_data()
{
//Label of form
// $data=array();
//$data['fid'] =array();
//$data['stud_class'] = '';
//$data['up_std_name'] = array();
//$data['up_std_address']=array();
$data['fid'] ='';
$data['up_std_name'] = '';
$data['up_std_address']='';
$data['stud_class'] = '';
$data['up_std_language']='';
$data['up_std_gender']='';
$data['up_std_birthdate']='';
$data['up_std_photo']='';
//echo "ddddddd";
// print_r($data['up_std_address']);
//$data['std_name1']="Name";
//$data['std_address1']="Address";
//$data['std_class']="Class";
// $data['up_std_class_list']=array(
// 'select' => 'Select',
// '10th' => '10th',
// '12th' => '12th',
// 'Graduate' => 'Graduate'
// );
//$data['std_language1']="Language";
//$data['std_gender1']="Gender";
//$data['std_birthdate']="Birthdate";
//$data['std_photo']="Photo";
//$dat['std_int_language']="Interested Language";
//values get from the database
//$data['fid']['value'] = 0;
//print_r($data['fid']['value']);
// $data['up_std_name'] = array(
// 'name' => 'std_name',
// 'id' => 'std_name',
// 'maxlength' => '50',
// 'size' => '30',
// 'style' => 'width:30%'
// );
// $data['up_std_address']=array(
// 'name'=>'std_address',
// 'id'=>'std_address',
// 'rows'=>'2',
// 'columns'=>'5',
// 'width'=>'20',
// 'size'=>'50',
// 'maxlength' => '100',
// 'style'=>'width:30%'
// );
// $data['up_std_language']=
// array('name'=>'std_language',
// 'value'=>'.Net',
// 'checked'=>True
// );
// (array('name'=>'std_language',
// 'value'=>'PHP',
// 'checked'=>false
// )
// );
// (array('name'=>'std_language',
// 'value'=>'JAVA',
// 'checked'=>false
// )
// );
// (array('name'=>'std_language',
// 'value'=>'Android',
// 'checked'=>false
// )
// );
// (array('name'=>'std_language',
// 'value'=>'Iphone',
// 'checked'=>false
// )
// );
//print_r($data['up_std_language']);
// $data['up_std_gender']=(array
// (
// "name"=>"std_gender",
// "id"=>"std_gender",
// "value"=>"M",
// 'checked'=>set_radio('std_gender', 'M', True)
// )
// );
// ?>
<?php
// (array
// (
// "name"=>"std_gender",
// "id"=>"std_gender",
// "value"=>"F",
// 'checked'=>set_radio('std_gender', 'F', True)
// )
// );
?>
<?php // $data['up_std_birthdate']=''; ?>
<td>
</td>
<?php
//$data['up_std_photo']='';
// $data['up_std_ilanguage']=array(
// 'select' => 'Select',
// '.Net' => '.Net',
// 'PHP' => 'PHP',
// 'JAVA' => 'JAVA',
// 'Android'=> 'Android',
// 'IPhone' => 'IPhone'
// );
?>
<?Php return $data;
}
}
?>
View:finalview.php
<?php
//echo validation_errors();
?>
<html lang="en">
<head>
<meta charset="utf-8">
<title></title>
<link rel="stylesheet" href="//code.jquery.com/ui/1.11.0/themes/smoothness/jquery-ui.css">
<script src="//code.jquery.com/jquery-1.10.2.js"></script>
<script src="//code.jquery.com/ui/1.11.0/jquery-ui.js"></script>
<link rel="stylesheet" href="/resources/demos/style.css">
<script>
$(function() {
$( "#datepicker" ).datepicker();
dateFormat: 'yyyy-mm-dd'
onclick="javascript: ('datepicker','yyyyMMdd','arrow',true,'12',true)"
});
</script>
</head>
<body>
<? echo form_open('delete/input');
//print_r($fid); ?>
<? echo form_hidden('id',$fid); ?>
<table>
<tr>
<td>
<label for='std_name'>Student Name</label>
</td>
<td>
<?php
$data = array(
'name' => 'std_name1',
'id' => 'std_name1',
'maxlength' => '100',
'size' => '50',
//'value' => set_value('std_name1'),
'style' => 'width:50%'
);
//echo form_input('std_name1',set_value('std_name1'));
echo form_input('std_name1',$up_std_name);
//print_r($up_std_name);
//echo $std_name1;
//print_r($std_name1);
?></td>
</tr>
<tr>
<td>
<label for='std_address'>Address</label>
</td>
<td>
<?php
$data=array(
'name'=>'std_address1',
'id'=>'std_address1',
'rows'=>'3',
'columns'=>'3',
'size'=>'50',
'maxlength' => '100',
'style'=>'width:50%'
);
echo form_textarea('std_address1',$up_std_address);
print_r($up_std_address);
?>
</td>
</tr>
<tr>
<td>
<label for='std_class'>Class</label>
</td>
<td>
<?php
$options = array(
'select' => 'Select',
'10th' => '10th',
'12th' => '12th',
'Graduate' => 'Graduate'
);
echo form_dropdown('std_class',$options,$stud_class);
print_r($stud_class);
?></td>
<tr>
<td>
<label for='std_language'>Language</label>
</td>
<td>
<?php
// $query['']=array('.Net'=>'.Net','PHP'=>'PHP');
// print_r($query);
//echo "----charmi---";
// print_r($up_std_language);
// print_r($data['up_std_language']['value']);
// print_r($language);
//echo "bbb";
//echo "<br/>";
//echo set_checkbox(in_array('std_language', $language) // TRUE checks the box, FALSE does no
// );
$language = explode(',',$up_std_language);
$a='';
$b='';
$c='';
$d='';
$e='';
//print_r($t);
// if(isset ($this->input->post['std_language1'])) {
// $role = implode(',', $this->input->post('std_language1'));
// print_r($role);
// } else {
// $role = '';
// }
if(in_array('.Net',$language))
{
$a='checked="checked"';
//echo $a;
}
if(in_array('PHP',$language))
{
$b='checked="checked"';
//echo $b;
}
if(in_array('JAVA',$language))
{
$c='checked="checked"';
}
if(in_array('Android',$language))
{
$d='checked="checked"';
}
if(in_array('IPhone',$language))
{
$e='checked="checked"';
}
// $skill = implode(',', $this->input->post('skill'));
//$data['skill'] = $skill;
echo form_checkbox('std_language1','.Net',$a). ".Net";
echo form_checkbox('std_language1','PHP',$b)."PHP";
echo form_checkbox('std_language1','JAVA',$c)."JAVA";
echo form_checkbox('std_language1','Android',$d)."Android";
echo form_checkbox('std_language1','IPhone',$e)."IPhone";
$t=$this->input->post('std_language1';
echo "***";
echo $t;
//print_r($t);
//print_r($language);
$v=$language;
print_r ($v);
if(isset($t))
{
$q=implode(',',$this->input->post['std_language1'] );
echo "(((((";
print_r($q);
//$data['q']=$q;
//print_r($data);
}
// else
// {
// $q='';
// }
// echo $q;
?>
</td>
</tr>
<tr>
<td>
<label for='std_gender'>Gender</label>
</td>
<td>
<?php
//echo $gender=$this->input->post('std_gender1');
// if($gender=='male' || empty($gender)) $mchecked=true;
// else if($gender=='female') $fchecked=true;
// if($gender=="male")
// {
// echo "checked";
// }
// echo form_radio('std_gender1', 'male', #$mchecked, 'id=male').form_label('Male', 'male');
// echo form_radio('std_gender1', 'female', #$fchecked, 'id=female').form_label('Female','female');
//print_r($up_std_gender);
// $checked = '';
// if($checked)
// {
// $checked='F';
//echo $checked;
//$false='M';
// }
// else
// {
// $checked='M';
//$false='F';
// }
// echo form_radio('std_gender1', 'M', $checked)."Male";
// echo form_radio('std_gender1', 'F', $checked)."Female";
$gender=array(
'name'=>'std_gender1',
'id'=>'std_gender1'
//'checked'=>set_value('std_gender1', 'F', FALSE)
);
echo "=======";
print_r($up_std_gender);
// $checked = '';
$w='M';
$m='F';
if($up_std_gender)
{
$w='checked="checked"';
}
else
if($up_std_gender)
{
$m='checked="checked"';
}
//echo $checked;
// $false='M';
// }
// else
// {
// $checked='M';
// $false='F';
// }
echo form_radio('std_gender1', 'M',$w)."Male";
echo form_radio('std_gender1', 'F',$m)."Female";
// echo form_radio($gender,$up_std_gender,set_value('std_gender1', 'F', TRUE))."Male";
// echo form_radio($gender,'F',set_value('std_gender1', 'M', TRUE))."Female";
// echo form_radio(array
// (
// "name"=>"std_gender1",
// "id"=>"std_gender1",
// "value"=>"F",
// 'checked'=>set_value('std_gender1', 'F', FALSE)
// )
// );
// ?>
<?php
// echo form_radio(array
// (
// "name"=>"std_gender1",
// "id"=>"std_gender1",
// "value"=>"M",
// 'checked'=>set_value('std_gender1', 'M', FALSE)
// )
// );
?>
</td>
</tr>
<tr>
<td valign="top">
<label for='std_birthdate'>Birthdate</label>
</td>
<?php
$date=array(
'name'=>'datepicker',
'id'=>'datepicker'
);
?>
<td><?php echo form_input($date,$up_std_birthdate); ?><!--<input type="text" id="datepicker" name="datepicker" />--></td>
</tr>
<tr>
<td>
<label for='std_photo'>Photo</label>
</td>
<td>
<?php //echo $error;?>
<?php echo form_open_multipart('student/do_upload');
echo form_upload('userfile',$up_std_photo);
echo form_label($up_std_photo);
?>
<!--<input type="file" name="userfile" size="20" />-->
<?php echo form_close();?>
</td>
</tr>
<tr>
<td>
<label for='std_ilanguage[]'>Interested Language</label>
</td>
<td>
<!--<select size="" name="ilanguage[]" multiple="multiple">
<option>.Net</option>
<option>PHP</option>
<option>JAVA</option>
<option>Android</option>
<option>IPhone</option>
</select>-->
<?php
$options = array(
'select' => 'Select',
'.Net' => '.Net',
'PHP' => 'PHP',
'JAVA' => 'JAVA',
'Android'=> 'Android',
'IPhone' => 'IPhone'
);
//$select=array('.Net','PHP','JAVA','Android','IPhone');
echo form_multiselect('std_ilanguage',$options);
?></td>
</tr>
<tr>
<td>
<? echo form_submit('btnupdate','Update!'); ?>
</td>
</tr>
</table>
<p><?php echo anchor('delete/test','Go To View!'); ?></p>
</form>
</html>
<? echo form_close(); ?>
I'm using implode() function but it doesn't get the updated vales so give me solution
Here, all the records of default value is shown into controls but when I checked more than one, it will update only single a checkbox.
Thanks again.
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.
Call to a member function result() on a non-object
There is an error message when my view is being loaded. "Call to a member function result() on a non-object" How do I fix this? This is the loop in my View: discussion/view.php <?php foreach ($query->result() as $result) : ?> <tr> <td> <?php echo anchor('comments/index/'.$result->ds_id,$result->ds_title) . ' ' . $this->lang->line('comments_created_by') . $result->usr_name; ?> <?php echo anchor('discussions/flag/'.$result->ds_id, $this->lang->line('discussion_flag')) ; ?> <br /> <?php echo $result->ds_body ; ?> </td> </tr> <?php endforeach ; ?> and this is the function index in my Comments Controller: public function index() { if ($this->input->post()) { $ds_id = $this->input->post('ds_id'); } else { $ds_id = $this->uri->segment(3); } $page_data['discussion_query'] = $this->Discussions_model->fetch_discussion($ds_id); $page_data['comment_query'] = $this->Comments_model->fetch_comments($ds_id); $page_data['ds_id'] = $ds_id; $this->form_validation->set_rules('ds_id', $this->lang->line('comments_comment_hidden_id'), 'required|min_length[1]|max_length[11]'); $this->form_validation->set_rules('comment_name', $this->lang->line('comments_comment_name'), 'required|min_length[1]|max_length[25]'); $this->form_validation->set_rules('comment_email', $this->lang->line('comments_comment_email'), 'required|min_length[1]|max_length[255]'); $this->form_validation->set_rules('comment_body', $this->lang->line('comments_comment_body'), 'required|min_length[1]|max_length[5000]'); if ($this->form_validation->run() == FALSE) { $this->load->view('common/header'); $this->load->view('nav/top_nav'); $this->load->view('comments/view', $page_data); $this->load->view('common/footer'); } else { $data = array('cm_body' => $this->input->post('comment_body'), 'usr_email' => $this->input->post('comment_email'), 'usr_name' => $this->input->post('comment_name'), 'ds_id' => $this->input->post('ds_id') ); if ($this->Comments_model->new_comment($data)) { redirect('comments/index/'.$ds_id); } else { // error $this->data['message'] = 'Error!'; } } }
article post not updating in codeigniter blog
I am new in codeigniter. I build a cms with codeigniter for blog. But when i want edit a article post and want to save it, it create new one post not update old post which i edited. Please help me. My Article Edit crontroller: public function edit ($id = NULL) { // Fetch a article or set a new one if ($id) { $this->data['article'] = $this->article_m->get($id); count($this->data['article']) || $this->data['errors'][] = 'article could not be found'; } else { $this->data['article'] = $this->article_m->get_new(); } // categories for dropdown $this->data['all_categories'] = $this->article_m->join(); // Set up the form $rules = $this->article_m->rules; $this->form_validation->set_rules($rules); // Process the form if ($this->form_validation->run() == TRUE) { $data = $this->article_m->array_from_post(array( 'title', 'extra_title', 'slug', 'image', 'category_id', 'body', 'pubdate' )); $this->article_m->save($data, $id); redirect('admin/article'); } // Load the view $this->data['subview'] = 'admin/article/edit'; $this->load->view('admin/_layout_main', $this->data); } My Models: public function array_from_post($fields){ $data = array(); foreach ($fields as $field) { $data[$field] = $this->input->post($field); } return $data; } public function get($id = NULL, $single = FALSE){ if ($id != NULL) { $filter = $this->_primary_filter; $id = $filter($id); $this->db->where($this->_primary_key, $id); $method = 'row'; } elseif($single == TRUE) { $method = 'row'; } else { $method = 'result'; } if (!count($this->db->ar_orderby)) { $this->db->order_by($this->_order_by); } return $this->db->get($this->_table_name)->$method(); } public function get_by($where, $single = FALSE){ $this->db->where($where); return $this->get(NULL, $single); } public function save($data, $id = NULL){ // Set timestamps if ($this->_timestamps == TRUE) { $now = date('Y-m-d H:i:s'); $id || $data['created'] = $now; $data['modified'] = $now; } // Insert if ($id === NULL) { !isset($data[$this->_primary_key]) || $data[$this->_primary_key] = NULL; $this->db->set($data); $this->db->insert($this->_table_name); $id = $this->db->insert_id(); } // Update else { $filter = $this->_primary_filter; $id = $filter($id); $this->db->set($data); $this->db->where($this->_primary_key, $id); $this->db->update($this->_table_name); } return $id; } public function get_new () { $article = new stdClass(); $article->title = ''; $article->extra_title = ''; $article->slug = ''; $article->image = ''; $article->category_id = ''; $article->body = ''; $article->pubdate = date('Y-m-d'); return $article; } public function join() { $this->db->select('name,categories.id as category_id'); $this->db->from($this->_table_name); $this->db->join('categories', 'categories.id = category_id','right'); $Q = $this->db->get(); if ($Q->num_rows() > 0){ foreach ($Q->result_array() as $row){ $data[$row['category_id']] = $row['name']; } } $Q->free_result(); return $data; } My View: <?php echo validation_errors(); ?> <?php echo form_open_multipart('admin/article/edit'); ?> <table class="table"> <tr> <td>Publication date</td> <td><?php echo form_input('pubdate', set_value('pubdate', $article->pubdate), 'class="datepicker"'); ?></td> </tr> <tr> <td>Category</td> <td><?php $js = 'id="category_id" onChange="some function();"'; echo form_dropdown('category_id', $all_categories, set_value('category_id', $article->category_id), $js); ?></td> </tr> <tr> <td>Title</td> <td><?php echo form_input('title', set_value('title', $article->title)); ?></td> </tr> <tr> <td>Extra Title (Optional)</td> <td><?php echo form_input('extra_title', set_value('extra_title', $article->extra_title)); ?></td> </tr> <tr> <td>Slug</td> <td><?php echo form_input('slug', set_value('slug', $article->slug)); ?></td> </tr> <tr> <td>Upload Image</td> <td> <div class="input-append"> <?php echo form_input('image', set_value('image', $article->image),'id="fieldID"'); ?> Select </div> </td> </tr> <tr> <td>Body</td> <td><?php echo form_textarea('body', set_value('body', $article->body), 'class="tinymce"'); ?></td> </tr> <tr> <td></td> <td><?php echo form_submit('submit', 'Save', 'class="btn btn-primary"'); ?></td> </tr> </table> <?php echo form_close();?> Please Help Me.
You have to pass the id to the controller. In your view you are telling the form to submit to article/edit but not the id. <?php echo validation_errors(); ?> <?php echo form_open_multipart('admin/article/edit/'.$article->id); ?> ... You'll probably get some warnings if $article is not set, so you may want to put in some checks for when you're adding a new item.
Undefined Variable taskid in view
i am working on view and i want to print task id from database in my view following is my Controller function Controller :- function editMilestone($editid){ //, $taskid) { if ($this->session->userdata('logged_in')) { $session_data = $this->session->userdata('logged_in'); $id = $session_data['id']; $username = $session_data['username']; $is_master_admin = $session_data['master']; $imagethumb = $session_data['imagethumb']; $status_result = $this->getstatus->getEnumValues(MILESTONE, 'status'); $result = $this->milestonemodel->getEditMilestone($editid , $taskid); $pendingbug = $this->bugmodel->getBug($id, $is_master_admin); $pendingtask = $this->taskmodel->getTask($id, $is_master_admin); if ($result == true) { $session_msg_data = $this->session->userdata('msg'); if (isset($session_msg_data) && !empty($session_msg_data)) { $milestonemsg = isset($session_msg_data['milestonemsg']) ? $session_msg_data['milestonemsg'] : ''; $milestoneopt = isset($session_msg_data['milestoneopt']) ? $session_msg_data['milestoneopt'] : ''; $this->session->unset_userdata('msg'); } else { $milestonemsg = ''; $milestoneopt = ''; } $data = ''; $data = array('username' => $username, 'is_master_admin' => $is_master_admin, 'imagethumb' => $imagethumb, 'result' => $result, 'taskid' => $taskid, //'editid'=>$editid, 'status_result' => $status_result, 'profileopt' => $milestoneopt, 'profilemsg' => $milestonemsg, 'pendingtask' => $pendingtask, 'pendingbug' => $pendingbug ); $this->load->view('milestone/edit_milestone', $data); } else { redirect('task', 'refresh'); } } else { //If no session, redirect to login page redirect('home/logout', 'refresh'); } } Model :- function getEditMilestone($id){ //, $taskid) { $status = array(PUBLISH, UNPUBLISH, BLOCK); $this->db->select('*'); $this->db->from(MILESTONE); $this->db->where('id', $id); //$this->db->where('taskid', $taskid); $this->db->where_in('status', $status); $this->db->limit(1); //echo $this->db-last_query(); $query = $this->db->get(); if ($query->num_rows() == 1) { return $query->result(); } else { return false; } } VIEW :- Milestone View <div class="message"> <span class="arrow"></span> <span class="body"> <?php echo '<b> <U> Task Title </U>:- </b>  '; echo $milestone_row->tasktitle; echo '<br/>'; echo '<b> <U> Workspace Title </U>:- </b>  '; echo $milestone_row->workspacetitle; echo '<br/>'; echo '<b> <U> Description </U>:- </b>  '; echo $milestone_row->description; echo '<br/>'; echo '<b> <U> Hours </U>:- </b>  '; echo $milestone_row->esthours; echo 'hrs'; echo '<br/>'; echo '<b> <U> Minutes </U>:- </b>  '; echo $milestone_row->estmin; echo'mins'; echo '<br/>'; ?> Edit </div> When i click on edit link from above view it will transfer to editMilestone from controller and it wil transfer to to another view that is edit_milestone View :- edit_milestone <?php $attributes = array('class' => 'form-horizontal', 'id' => 'form_add_milestone'); echo form_open('milestone/validateEditMilestone/'.$result[0]->id.'/'.$taskid, $attributes); ?> <input type="text" readonly="readonly" value="<?php echo $taskid; ?>" name="taskid" /> I would like to print my taskid here from database
The problem is with the code. you are using $taskid when its not initialized in following line, $result = $this->milestonemodel->getEditMilestone($editid , $taskid); and when you put that value in $data it does not work because there is no value in $taskid you should pass $taskid as parameter in Milestone View or create another query to fetch it from db.
PHP Todo CheckList Checked Feature
I need help with a PHP ToDo List. I have most of it working except for the check box to move it from a completed list to a still need to do list. here is the code I have so far: For the edit screen: %% views/header.html %% <h1>{{$title}}</h1> <div class='inputs'> <form action="##todo/update##" method="post"> <input type="hidden" id="id" name="id" value="{{$todo['id']}}" /> <label for="description">Description:</label> <input type="text" id="description" name="description" value="{{$todo ['description']}}" /> <label for="done">Done?:</label> <input type="checkbox" id="done" name="done" value="1" /> <input type="submit" value="Update" /> <form> </div> <p><< Back</p> %% views/footer.html %% For the todo.inc file: <?php include_once "include/util.inc"; include_once "models/todo.inc"; function safeParam($arr, $index, $default) { if ($arr && isset($arr[$index])) { return $arr[$index]; } return $default; } function get_view($params) { $id = safeParam($params, 0, false); if ($id === false) { die("No todo id specified"); } $todo = findToDoById($id); if (!$todo) { die("No todo with id $id found."); } // #formatter:off renderTemplate( "views/todo_view.inc", array( 'title' => 'Viewing To Do', 'todo' => $todo ) ); // #formatter:on } function get_list($params) { $todos = findAllCurrentToDos(); $dones = findAllDoneToDos(); // #formatter:off renderTemplate( "views/index.inc", array( 'title' => 'To Do List', 'todos' => $todos, 'dones' => $dones ) ); // #formatter:on } function get_edit($params) { $id = safeParam($params, 0, false); if (!$id) { die("No todo specified"); } $todo = findToDoById($id); if (!$todo) { die("No todo found."); } // #formatter:off renderTemplate( "views/todo_edit.inc", array( 'title' => 'Editing To Do', 'todo' => $todo ) ); // #formatter:on } function post_add($params) { if (!isset($_POST['description'])) { die("no description given"); } $description = htmlentities($_POST['description']); addToDo($description); redirectRelative("index"); } function validate_present($elements) { $errors = ''; foreach ($elements as $element) { if (!isset($_POST[$element])) { $errors .= "Missing $element\n"; } } return $errors; } function post_update($params) { $errors = validate_present(array('id', 'description', 'done')); if ($errors) { die($errors); } $id = $_POST['id']; $description = $_POST['description']; $done = $_POST['done']; updateToDo($id, $description, $done); redirectRelative("todo/view/$id"); } function get_delete($params) { $id = safeParam($params, 0, false); if (!$id) { die("No todo specified"); } $todo = findToDoById($id); if (!$todo) { die("No todo found."); } deleteToDo($id); redirectRelative("index"); } ?>
Your error is in these two functions. function validate_present($elements) { $errors = ''; foreach ($elements as $element) { if (!isset($_POST[$element])) { $errors .= "Missing $element\n"; } } return $errors; } function post_update($params) { $errors = validate_present(array('id', 'description', 'done')); if ($errors) { die($errors); } $id = $_POST['id']; $description = $_POST['description']; $done = $_POST['done']; updateToDo($id, $description, $done); redirectRelative("todo/view/$id"); } You are attempting to validate that done exists in validate_present when called by post_update. done obviously cannot exists since it is not sent to the server when the checkbox is not checked. The $_POST does not even contain that variable, so it returns that element is missing (since it technically is). I would leave validate_present alone and change post_update as follows: function post_update($params) { $errors = validate_present(array('id', 'description')); if ($errors) { die($errors); } $id = $_POST['id']; $description = $_POST['description']; $done = (isset($_POST['done'])? 1 : 0); updateToDo($id, $description, $done); redirectRelative("todo/view/$id"); }