【问题标题】:codeigniter A Database Error Occurred Error Number: 1054codeigniter 发生数据库错误错误号:1054
【发布时间】:2017-01-10 10:14:20
【问题描述】:

发生数据库错误
错误编号:1054
“字段列表”中的未知列“un”
更新student SET un = NULL,pw = NULL,n = NULL WHERE 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>

【问题讨论】:

  • 什么是数据库结构?
  • 更好地编辑您的问题

标签: php database codeigniter


【解决方案1】:

已经在你的“学生”数据库中没有'un'列中说你的错误。

您还更改了获取发布变量的方法。 用这个获取$this-&gt;input-&gt;post("form_input_name")

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

【讨论】:

    猜你喜欢
    • 2017-06-06
    • 1970-01-01
    • 2018-03-16
    • 2018-09-18
    • 2013-11-18
    • 2018-04-15
    • 2015-06-28
    • 2017-07-31
    • 2014-05-17
    相关资源
    最近更新 更多