I am trying to enter some data which I post to the server via jquery.post into a database.
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");
}
});
Here is my codeigniter php code for the controller to which the data is being sent:
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
}
Now I have a database table called posts with the fields: id, title, message.
I want to insert the passed set of data into the database.
Questions: -Do the names in the jQuery object that i send to the server have to be the same as the field names in the database to be able to use the codeigniter $this->db->insert('mytable', $data); method?
-How would i go about inserting the values title
and message
without explicitly specifying at which id
i want to insert them so that this dataset will just be added to the database in the first empty spot.