dongzong3053 2015-03-28 15:05
浏览 37

使用codeigniter更新数据库记录

I have been having a problem... a frustrating problem at that. I cannot seem to edit a specific row in Codeigniter. I have found previous questions on the same here, and even tried the solutions but to no avail. I am press for time on this project I am undertaking. Before you regard this question as a duplicate please have a look see. Any help will be greatly appreciated... Thank you in advance My code snippets are below:

Codeigniter/Controller

<?php..

    //Selects all from admin table
        function get_admin(){
                $data['query'] = $this->Superuser_Model->selectadmin();
        }
        //brings in the view
        // function editAdmin(){
        //  $data['content'] = 'admin/edit_admin';
        //  $this->load->view('include/template_back', $data);
        // }
        //click a specific row in the view (tabulated data)
        function edit($id){
            $data['array']= $this->Superuser_Model->editadmin($id);         
            // $data['content'] = 'admin/edit_admin';
            $this->load->view('include/header_back');
            $this->load->view('admin/edit_admin', $data);
            $this->load->view('include/footer_back');
        }
        //Should update the from
        function update_superuser(){
            $this->form_validation->set_rules('username','Username','required');
            $this->form_validation->set_rules('password','Password','required');
            if($this->form_validation->run()==FALSE)
            {
                $data['content'] = 'admin/add_admin';
                $this->load->view('include/template_back', $data);
            }
            else
            {
                $username = $this->input->post('username');
                $password = md5($this->input->post('password'));
                $date_added = $this->input->post('date_added');
                $this->Superuser_Model->update_superuser($username,$password,$date_added);
                redirect('login/index', 'refresh');
            }

        }
..?>

Codeigniter/Model

    <?php...
    function selectadmin(){
            // $id = $this->uri->segment(3);
            $query = $this->db->get('admin');       
            return $query->result_array();
        }
        function editadmin($id){
            $id = $this->uri->segment(3);
            $query = $this->db->get('admin');
            $this->db->where('adminID', $id);       
            return $query->result_array();
        }
        function update_superuser($data, $id){
            $this->uri->segment(3);
            $id = $this->input->post('adminID');
            $data = array(
                            'username'=> $this->input->post('username'),
                            'password'=> $this->input->post('password'),
                            'date_added'=> $this->input->post('date_added')
                        );
            $this->db->where('adminID', $id);
            $this->db->update('admin', $data);
        }
...?>

Codeigniter/View ...

<?php echo form_open('superuser/update_superuser', array('class' => 'form-horizontal', 'enctype' => 'multipart/form-data')); ?>
            <div class="panel panel-default">
              <div class="panel-heading">
                <div class="panel-btns">
                  <a href="#" class="panel-close">&times;</a>
                  <a href="#" class="minimize">&minus;</a>
                </div>
                <h4 class="panel-title">Admin Details</h4>
                <p>Please, Insert your details here below... (for Superuser use only)</p>
              </div>
              <div class="panel-body panel-body-nopadding">

                <!--username-->
                <div class="form-group">
                   <!-- <input type="hidden" name="adminID" class="form-control" value="<?php echo $array->adminID;?>"/> -->
                  <label class="col-sm-4 control-label">Username</label>
                  <div class="col-sm-8">
                    <input type="text" name="username" class="form-control" value="<?php echo $array['username'];?>"/>
                  </div>
                  // <?php // form_error('username');?>
                </div>
                <!--password-->
                <div class="form-group">
                  <label class="col-sm-4 control-label">Password</label>
                  <div class="col-sm-8">
                    <input type="password" name="password" class="form-control" value="<?php echo $array['password'];?>"/>
                  </div>
                  <?php //echo form_error('date_added');?>
                </div>
                <!--Date Added-->
                <div class="form-group">
                  <label class="col-sm-4 control-label">Date</label>
                  <div class="col-sm-8">
                    <input type="text" name="date_added" class="form-control" id="datepicker" value="<?php echo $array['date_added'];?>" />&nbsp;<img src="<?php echo base_url();?>components/backend/images/calendar.gif" alt=""  /><br /><br />
                  </div>
                  <?php //echo form_error('date_added');?>
                </div>

                </div><!-- panel-body -->
              <div class="panel-footer">
                <button class="btn btn-primary">Submit</button>
                <button type="reset" class="btn btn-default">Reset</button>
              </div><!-- panel-footer -->
            </div><!-- panel-default -->
          <?php form_close();?>
...</body></html>

Errors Displayed

A PHP Error was encountered

Severity: Notice

Message: Undefined index: username

Filename: admin/edit_admin.php

Line Number: 54
A PHP Error was encountered

Severity: Notice

Message: Undefined index: password

Filename: admin/edit_admin.php

Line Number: 62
A PHP Error was encountered

Severity: Notice

Message: Undefined index: date_added

Filename: admin/edit_admin.php

Line Number: 70
  • 写回答

3条回答 默认 最新

  • dqh1984 2015-03-28 15:36
    关注

    Seems like not correct $array['username'], $array['password'] and $array['date_added']. Print out $array first and you'll see what's wrong.

    评论

报告相同问题?

悬赏问题

  • ¥15 目详情-五一模拟赛详情页
  • ¥15 有了解d3和topogram.js库的吗?有偿请教
  • ¥100 任意维数的K均值聚类
  • ¥15 stamps做sbas-insar,时序沉降图怎么画
  • ¥15 买了个传感器,根据商家发的代码和步骤使用但是代码报错了不会改,有没有人可以看看
  • ¥15 关于#Java#的问题,如何解决?
  • ¥15 加热介质是液体,换热器壳侧导热系数和总的导热系数怎么算
  • ¥100 嵌入式系统基于PIC16F882和热敏电阻的数字温度计
  • ¥15 cmd cl 0x000007b
  • ¥20 BAPI_PR_CHANGE how to add account assignment information for service line