php - Codeigniter weird database error -


everytime insert new data post_id cannot null when check phpmyadmin. correct id stored.

i'm using ajax send id's view controller. i've tried alert(id) see if id selected , selected no problem in jquery part.

it works way want to, it's there error not stop insertion , can hide error fix without using that.

jquery

var post_id = $(this).closest('.portlet').find('.form').find('.postid').val();         var comment = $(this).closest('.comments').find('textarea').val();         alert("this post id "+post_id+"\nthis comment "+comment);         $(this).closest('.comments').submit();         $.ajax({             type: "post",             url: base_url+'classes/addcomment',             datatype: 'json',             data: {post_id: post_id, comment: comment},             async: false     }); 

in alert, can see id , comments , correct. i'm pretty sure there no problem in accessing.

controller

public function addcomment(){         $data = array(             'user_id' => $this->user_id,             'post_id' => $this->input->post('post_id'),             'content' => $this->input->post('comment')         );         $this->comment_model->addcomment($data);         redirect('/classes/ict141');     } 

the error

error number: 1048 column 'post_id' cannot null insert `post_comments` (`user_id`, `post_id`, `content`) values ('4', null, null) line number: 28 

line number 28 in model just

public function addcomment($data){      $this->db->insert('post_comments', $data);    } 

try changing :

var post_id = $(this).closest('.portlet').find('.form').find('.postid').val();         var comment = $(this).closest('.comments').find('textarea').val();         alert("this post id "+post_id+"\nthis comment "+comment);         $(this).closest('.comments').submit();         $.ajax({             type: "post",             url: base_url+'classes/addcomment',             datatype: 'json',             data: {"post_id" : post_id, "comment" : comment},             async: false     }); 

Comments

Popular posts from this blog

java - Date formats difference between yyyy-MM-dd'T'HH:mm:ss and yyyy-MM-dd'T'HH:mm:ssXXX -

c# - Get rid of xmlns attribute when adding node to existing xml -