Reputation: 37
I dont know why after clicking the "Add Button", the items that needs to insert into the database is NULL.
so here's my controller
public function addItem(){
$data = array(
"item_ID"=>$_POST['item_ID'],
"itemName"=>$_POST['itemName'],
"itemDescription"=>$_POST['itemDescription'],
"itemLink"=>$_POST['itemLink']
);
$orgID = $this->model->get_org();
$this->model->insertItem($data,$orgID);
}
and here's my model
public function insertItem($data,$orgID){
$this->db->insert('Items',$data);
$getID=$this->db->insert_id();
foreach($orgID as $temp):
$Organization_ID = $_POST[$temp->OrganizationID];
endforeach;
$SkillReq=$this->input->post('0');
$Skill_ReqID=$this->input->post();
$insertdata = array();
for($i=0; $i=count($orgID); $i++){
$insertdata[]=array(
'Skill_ReqID'=>$Skill_ReqID[$i],
'OrganizationID'=>$Organization_ID[$i],
'item_ID'=>$getID[$i],
'SkillReq'=>$SkillReq[$i]
);
}
$this->db->insert_batch('skillreqdept',$insertdata);
}
it actually inserts the rows that had been counted in orgID but there is no data, only the Auto Incremented skill_reqID has in it.
Upvotes: 1
Views: 264
Reputation: 38642
Ya, it should be empty. Check your array "
public function addItem(){
$data = array(
'item_ID"=>$_POST['item_ID'], <== wrong wrapping
'itemName"=>$_POST['itemName'],
'itemDescription"=>$_POST['itemDescription'],
'itemLink"=>$_POST['itemLink']
);
$orgID = $this->model->get_org();
$this->model->insertItem($data,$orgID);
}
If you're using proper IDE, it will highlight such a minor issues like this
As well insertdata
is any predefined PHP tag/function ??
As well what is this null[$i]
assign. I never heard of it.
Before do insert use print_r
to check data is in the correct format or not. print_r($insertdata); die;
Upvotes: 1
Reputation: 2036
I thing the issue is with Skill_ReqID'=>null[$i]
, I dont know what is null
variable.
Please try the following:
public function insertItem($data,$orgID){
$this->db->insert('Items',$data);
$getID=$this->db->insert_id();
foreach($orgID as $temp):
$Organization_ID = $_POST[$temp->OrganizationID];
endforeach;
$SkillReq=$this->input->post('0');
$insertdata = array();
for($i=0; $i=count($orgID); $i++){
$items=array(
'OrganizationID'=>$Organization_ID[$i],
'itemID'=>$getID[$i],
'SkillReq'=>$SkillReq[$i]
);
array_push($insertdata, $items);
}
$this->db->insert_batch('skillreqdept',$insertdata);
}
Upvotes: 1