簡體   English   中英

codeigniter發生數據庫錯誤,錯誤號:1054

[英]codeigniter A Database Error Occurred Error Number: 1054

發生數據庫錯誤
錯誤編號:1054
“字段列表”中的未知列“ un”
UPDATE student SET 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>

該錯誤已在您的“學生”數據庫中的“ 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');

暫無
暫無

聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.

 
粵ICP備18138465號  © 2020-2024 STACKOOM.COM