我正在尝试将发布的数据插入数据库,如下所示。
public function submit_signup(){
if($this->input->post('submit')){
$user_data['data']=array(
'username' => $this->input->post('username'),
'email' => $this->input->post('email'),
'password' => $this->input->post('password'),
'mobile' => $this->input->post('mobile')
);
}
$this->load->model('user_model');
if($this->user_model->register_user($user_data)){
echo 'data entered';
}
$this->load->view('templates/header');
$this->load->view('test',$user_data);
$this->load->view('templates/footer');
}
我的模型:
class user_model extends CI_Model {
public function __construct() {
parent::__construct();
}
public function register_user($data){
if(!$this->db->insert('user',$data)) {
echo 'Data not entered';
}
return true;
}
}
当我按下表单时,这就是我得到的
A PHP Error was encountered
Severity: Notice
Message: Array to string conversion
Filename: mysql/mysql_driver.php
需要你的帮助
最佳答案
将你的数组设为
$user_data=array(
'username' => $this->input->post('username'),
'email' => $this->input->post('email'),
'password' => $this->input->post('password'),
'mobile' => $this->input->post('mobile')
);
删除['data']
部分。然后将其用于插入查询
检查 manuall
关于php - 代码点火器 : insert data in database,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/37921625/