发生数据库错误
错误号码:1054
'字段列表'中的未知列'un' UPDATEstudent
SETun
= NULL,pw
= NULL,n
= NULL WHEREid
IS 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>
答案 0 :(得分:0)
在你的学生中已经有错误说你了#34;数据库没有&#39; un&#39;列。
此外,您还可以更改获取后置变量的方法。
用此获取$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');