Oke伙计们,我的codeignitter网站有一点问题,问题显示如下。
致命错误:在第88行的C:\ xampp \ htdocs \ scbdnet \ application \ models \ m_admin.php中的非对象上调用成员函数result()
代码显示如下:
模型
public function addUser()
{
$userid = $_POST['clientname'];
$userpassword = md5(12345);
$usernama = $_POST['completename'];
$useremail = $_POST['email'];
$usertelpon = $_POST['phone'];
$usernodesktop = $_POST['desktop'];
$usertypedesktop = $_POST['type'];
$usercompany = $_POST['company'];
$privilegeid = $_POST['level'];
$query=$this->db->query("INSERT INTO table_user (userId, userPassword, userName, userEmail, userTelp, userNoDesktop, userTypeDesktop, userCompany, fkPrivilegeId, userStatus)
VALUES ('$userid','$userpassword','$usernama','$useremail','$usertelpon','$usernodesktop','$usertypedesktop','$usercompany','$privilegeid','1');");
return $query->result(); //LINE 88
}
控制器
public function adduser_to_db(){
$this->load->model('m_admin');
$this->m_admin->addUser();
redirect('admin/user');
}
视图
<form action="<?php echo base_url();?>admin/adduser_to_db" method="POST" name="adduser" id="adduser">
<div class="row form-row">
<div class="col-md-12">
<input type="text" class="form-control" placeholder="New Username" name="clientname">
<input type="text" class="form-control" placeholder="Complete Name" name="completename">
<input type="text" class="form-control" placeholder="Email" name="email">
<input type="text" class="form-control" placeholder="Phone Ext." name="phone">
<input type="text" class="form-control" placeholder="Desktop no." name="desktop">
<input type="text" class="form-control" placeholder="Desktop type" name="type">
<input type="text" class="form-control" placeholder="Company" name="company">
<select id="level" style="width:100%" name="level">
<?php foreach($priv_list as $list){ ?>
<option value="<?php echo $list->privilegeId?>"><?php echo $list->privilegeStatus?></option><?php }?>
</select>
</div>
</div>
</div>
<div class="modal-footer">
<button type="button" class="btn btn-default" data-dismiss="modal">Close</button>
<button type="submit" class="btn btn-primary" name="adduser" id="adduser" value="adduser">Save changes</button>
</div>
</form>
任何想法的人?
答案 0 :(得分:0)
您不能在$query->result();
插入查询中使用does not populate any result
。它仅适用于选择查询。
但如果您想获取最后一个插入ID,则可以使用insert_id()
作为
$insertid = $this->db->insert_id();
您可以使用active record在表格中插入数据
$data = array(
'userId' => $_POST['clientname'] ,
'userPassword' => md5(12345) ,
'userName' => $_POST['completename'],
..... for all your column data
);
//then insert into table
$this->db->insert('table_user ', $data);
答案 1 :(得分:0)
$query->result(); does not work here
试试这个
public function addUser()
{
$userid = $_POST['clientname'];
$userpassword = md5(12345);
$usernama = $_POST['completename'];
$useremail = $_POST['email'];
$usertelpon = $_POST['phone'];
$usernodesktop = $_POST['desktop'];
$usertypedesktop = $_POST['type'];
$usercompany = $_POST['company'];
$privilegeid = $_POST['level'];
$query=$this->db->query("INSERT INTO table_user (userId, userPassword, userName, userEmail, userTelp, userNoDesktop, userTypeDesktop, userCompany, fkPrivilegeId, userStatus)
VALUES ('$userid','$userpassword','$usernama','$useremail','$usertelpon','$usernodesktop','$usertypedesktop','$usercompany','$privilegeid','1');");
if($query){
return true;
}else{
return flase;
}
}