我想输入一些数据,我通过jquery.post发布到服务器到数据库中。使用Codeigniter插入数据库
note = { // note object that will be sent to the server
title: $('input.xlarge').val(); ,
message: $('textarea.xlarge').val(); ,
}
$.post(link + "cart/addtodb", note,
function(data){
if(data == 'true'){
alert('Your note has been saved');
}else{
alert("Something went wrong");
}
});
这里是控制器我笨PHP代码的正在发送的数据:
public function addtodb()
{
$note = $this->input->post('note');
$this->postit_model->addnote($note);
echo 'true'; //send true response to client after note has been added to db
}
现在我有一个数据库表叫职位与字段:id, title, message.
我要插入的传递数据集到数据库中。
问题: - 我发送到服务器的jQuery对象中的名称必须与数据库中的字段名称相同才能使用codeigniter $ this-> db-> insert(' mytable',$ data);方法?
- 我将如何去插入值title
和message
而不明确指定我想插入它们的id
,这样这个数据集将被添加到第一个空白点的数据库中。
在$ data数组,由表名和other_table你指的领域,在这种情况下:标题和消息吗? – TheBaj
正确。对不起,错别字。我会更新答案。 – stormdrain