无法通过验证更新我的数据

时间:2018-07-11 06:55:46

标签: php codeigniter

我创建了具有正确验证的注册表格,并将其插入数据库中。现在我正在尝试更新记录,但我不知道为什么我的记录没有得到更新。请任何人让我知道我的记录未更新可能是什么问题。请从早上开始尝试,但无法获得理想的结果。即使验证也不起作用。请任何人查看我的代码,然后告诉我。

From.php(控制器)

        public function updatedata()
        {
        $id=$this->input->get('id');
        $result['data']=$this->Form_model->displayrecordsById($id);
        $this->load->view('update_records',$result);    

            if($this->input->post('update'))
            {
                $this->form_validation->set_rules('fname', 'First name', 'required');
                $this->form_validation->set_rules('lname', 'Last name', 'required');
                $this->form_validation->set_rules('username', 'Username', 'required|min_length[5]|max_length[12]|is_unique[form.username]');
                $this->form_validation->set_rules('email', 'Email', 'required|valid_email|is_unique[form.email]');

                if ($this->form_validation->run() == TRUE)
                {

                    $config['upload_path']   = './uploads/'; 
                    $config['allowed_types'] = 'gif|jpg|png'; 
                    $this->load->library('upload', $config);

                    if($this->upload->do_upload('filename'))
                    {
                        $fn=$this->input->post('fname');
                        $ln=$this->input->post('lname');
                        $un=$this->input->post('username');
                        $em=$this->input->post('email');
                        $fi = $this->upload->data('file_name');
                        $this->Form_model->updaterecords($fn,$ln,$un,$em,$fi,$id);
                        echo 'Successfully updated your record';
                    }
                }
            }
        }

From_model.php

    //get values 
    function displayrecordsById($id)
    {
        $query=$this->db->query("select * from form where ID='".$id."'");
        return $query->result();
    }

    //update record
    function updaterecords($fn,$ln,$un,$em,$fi,$id)
    {
        $query=$this->db->query("update form SET first_name='$fn',last_name='$ln',username='$un',email='$em',filename='$fi' where ID='".$id."'");
    }

update_records.php

    <body>
    <?php
      $i=1;
      foreach($data as $row)
      {
      ?>
        <?php echo form_open_multipart(''); ?>

                <div class="container">

                    <h5 style="color:#ff1a1a">First name</h5>
                    <input type="text" class="form-control" name="fname" value="<?php echo $row->first_name; ?>"/>
                    <span class="text-danger"><?php echo form_error("fname");?></span>

                    <h5 style="color:#ff1a1a">Last name </h5>
                    <input type="text" class="form-control" name="lname" value="<?php echo $row->last_name; ?>"/>
                    <span class="text-danger"><?php echo form_error("lname");?></span>

                    <h5 style="color:#ff1a1a">Username</h5>
                    <input type="text" class="form-control" name="username" value="<?php echo $row->username; ?>"/>
                    <span class="text-danger"><?php echo form_error("username");?></span>

                    <h5 style="color:#ff1a1a">E-mail</h5>
                    <input type="text" class="form-control" name="email" value="<?php echo $row->email; ?>"/>
                    <span class="text-danger"><?php echo form_error("email");?></span>

                    <h5 style="color:#ff1a1a">Image</h5>
                    <img src="<?php echo base_url('uploads/' . $row->filename);?>" class="img-responsive" alt="image" width="100px" height="100px"><br><input type="file" name="filename" value="">

                    <br><input type="submit" name="update" class="btn btn-success" value="Update Records"/></td>

                </div>

        </form>
        <?php } ?>
    </body>

0 个答案:

没有答案