i making student management system , want update record, code works fine update operation not done also, select elements dropdown, radio button not checked data in database. please help?
code controller:
//code edit student record. public function edit($stu_id){ $this->load->model('model_editstudent'); $data['r']=$this->model_editstudent ->get_student_row($stu_id); $this->load->view('view_editstudent', $data); } #update query. function update(){ $stu_id=$this->input->post('stu_id'); $data=array( 'name'=>$this->input->post('name'), 'address'=>$this->input->post('address'), 'sex'=>$this->input->post('sex'), 'yop'=>$this->input->post('yop'), 'interest'=>$this->input->post('interest')); $this->db->where('stu_id',$stu_id); $this->db->update('stu_record',$data); redirect('student_controller/'); } code model:
<?php if ( ! defined('basepath')) exit('no direct script access allowed'); class model_editstudent extends ci_model{ function get_student_row($stu_id){ $this->db->where('stu_id',$stu_id); $query=$this->db->get('stu_record'); #will return 1 record(row) return $query->row(); } } code view:
<form method="post" action='<?php echo site_url("student_controller/update"); ?>'> <b>student id:</b><br> <input type="text" name="name" readonly value="<?php echo $r->stu_id ?>"><br><br> <b>name of student:</b><br> <input type="text" name="name" value="<?php echo $r->name ?>"><br><br> <b>address:</b><br> <textarea name="address" rows="5" cols="22" ><?php echo $r->address ?></textarea><br><br> <b>gender:</b><br> <input type="radio" name="sex" value="<?php if($r->sex=='male') ?>">male<br> <input type="radio" name="sex" value="<?php if($r->sex=='female') ?>">female<br><br> <b>expected year of passing:</b><br> <select name="yop" value="<?php echo $r->yop ?>"> <option value="0">select year</option> <option value="2010">2010</option> <option value="2011">2011</option> <option value="2012">2012</option> <option value="2013">2013</option> <option value="2014">2014</option> <option value="2015">2015</option> </select><br><br> <b>extra curricular interests:</b><br> <input type="checkbox" name="interest" value="sports"><label>sports</label><br/> <input type="checkbox" name="interest" value="programming"><label>programming</label><br/> <input type="checkbox" name="interest" value="arts"><label>arts</label><br/> <input type="checkbox" name="interest" value="music"><label>music</label><br/> <br><input type="submit" value="update">   <a href='<?php echo site_url('student_controller/'); ?>'>cancel</a> </form>
first thing change select to
<select name="yop"> <option value="0">select year</option> <option value="2010" <?php if($r->yop=="2010"){echo "selected=selected";}?>>2010</option> <option value="2011" <?php if($r->yop=="2011"){echo "selected=selected";}?>>2011</option> <option value="2012" <?php if($r->yop=="2012"){echo "selected=selected";}?>>2012</option> <option value="2013" <?php if($r->yop=="2013"){echo "selected=selected";}?>>2013</option> <option value="2014" <?php if($r->yop=="2014"){echo "selected=selected";}?>>2014</option> <option value="2015" <?php if($r->yop=="2015"){echo "selected=selected";}?>>2015</option> </select> radio button to
<input type="radio" name="sex" value="male" <?php if($r->sex=='male') echo "checked";?>">male<br> <input type="radio" name="sex" value="female" <?php if($r->sex=='female') echo "checked"; ?>">female<br><br>
Comments
Post a Comment