代码点火器发生数据库错误错误编号:1054


codeigniter A Database Error Occurred Error Number: 1054

发生数据库错误
错误编号:1054
"字段列表"中的未知列"un">
更新student设置un=NULL,pw=NULL,n=NULL其中id为NULL
文件名:D:''Install''wamp''www''ci''system''database''DB_driver.php
线路编号:331

我需要帮助。我的完整代码是:

editcon.php:--

//Controller
<?php
  class editcon extends CI_Controller
  {
   function edit()
   {
    $id = $this->input->get('id');
    $this->load->model('editmodel');
    $dis['info']=$this->editmodel->getuserid($id);
    $this->load->view('editview',$dis);
   }
   function update()
   {
    $id = $this->input->post['uid'];
    $username = $this->input->post['un'];
    $password = $this->input->post['pw'];
    $stdname = $this->input->post['n'];
    $data = array('un'=>$username,'pw'=>$password,'n'=>$stdname);
       $this->load->model('editmodel');
       if($this->editmodel->updatebyid($data,$id))
       {
           $list['info'] = $this->listmodel->std_list();
       $this->load->view('listview',$list);
       }else
       {
        echo "error";
       }
   }
  }
?>
//editmodel:-                                      //model
<?php
   class editmodel extends CI_Model
   {
      function getuserid($id)
      {
       $this->load->database();
       $this->db->where('id',$id);
       $query = $this->db->get('student');
       return $query->result();
      }
       function updatebyid($data,$id)
      {
       $this->load->database();
       $this->db->where('id',$id)
                ->update('student',$data);
       return true;
      }
   }
?>
//editview:-                    //view
<html>
    <head><title>Student Edit</title></head>
    <body>
    <?php
      if(isset($data))
      {
       ?>
        <h1>Update Form</h1>
              <?php echo form_open('editcon/update'); ?>
              <table>
            <tr>
             <td>User name</td>
             <input type="hidden" name="uid" value="<? echo $info[0]->id?>">
             <td><input type="text" name="un" 
              value="<?php 
              foreach($info as $row)
              {
              echo $row->uname;
              } 
              ?>">
              </td>
            </tr>
            <tr>
             <td>Password</td>
             <td><input type="text" name="pw" value="<?php echo $info[0]->pword; ?>"</td>
            </tr>
            <tr>
             <td>Name</td>
             <td><input type="text" name="n" value="<?php echo $info[0]->sname; ?>"</td>
            </tr>
            <tr>
             <td><input type="submit" value="update" name="s1"></td>
            </tr>
           </table>
         </form>
    <?php
      }else
      {
         ?>
      }
    </body>
</html>
//listview:                             //view     //in here pass id on edit link
<html>
 <head><title>Listview</title></head>
 <body>
 <center>
        <table border="2">
            <tr>
             <td>Username</td>
             <td>Password</td>
             <td>Name</td>
            </tr>
            <?php foreach($info as $row)
                {
             ?>
             <tr>
             <?php $id=$row->id; ?>
             <td><?php echo $row->uname; ?></td>
             <td><?php echo $row->pword; ?></td>
             <td><?php echo $row->sname; ?></td>
             <td><a href="http://localhost/ci/editcon/edit/?id=<?php echo $id; ?>">edit</a></td>
            </tr>
         <?php } ?>
        </table>
   </center> 
 </body>
</html>

在您的"student"数据库中,已经有错误表明您没有"un"列。

此外,您还可以更改获取后变量的方法。用这个获取$this->input->post("form_input_name")

$id = $this->input->post('uid');
$username = $this->input->post('un');
$password = $this->input->post('pw');
$stdname = $this->input->post('n');