问题
I am using CodeIgniter, I am getting dynamically select boxes. From the second select box, the user can select the status and according to the status input field will display.
Check this below screenshot, If the user clicked on Add More
then below select box will display.
Now from the second select box, I choose Status one
so according to the selected value, remark input field displayed. Check below screenshot.
If the user wants more fields for ID 2 then the user will click on add Bank
. For example, I clicked two times and I chose a status. so It will display like this. because Each row has one status field.
There is no issue in UI till now, Now I am submitting the data into the database. But when I am submitting the data into the database then I am getting the error Message: Uninitialized string offset: 0
and sometimes Message: Uninitialized string offset: 1
.
The issue I am getting on the second dropdown because according to selected value input field displaying and If I choose Status one
then remark field is getting the value but date and remark and amt and reason are showing offset: 1
error for the first row.
You can find my HTML here: https://jsfiddle.net/7vthpbmc/
I am using below logic. My controller code is
public function insertProcess(){
$order = $this->input->post('pp_order[]');
$partner = $this->input->post('parner[]');
$status = $this->input->post('pp_fileStatus[]');
//$status output
Array (
[0] => 1
[1] => 2
[2] => 3
)
//it will increase and some time it will be duplicate
foreach ($status as $key) {
if (($key == 1)) {
$remark = $this->input->post('remark[]');
}
else{
$remark="";
}
if(($key == 2)){
$reasonDate = $this->input->post('reasonDate[]');
$message = $this->input->post('message[]');
}
else{
$reasonDate="";
$message="";
}
if(($key == 3)){
$reasonAmt = $this->input->post('reasonAmt[]');
$reason = $this->input->post('reason[]');
}
else{
$reasonAmt="";
$reason="";
}
}
$order_length = sizeof($order);
for ($j=0; $j < $order_length ; $j++) {
$data['row']=array(
'order' => $order[$j],
'partner' => $partner[$j],
'status' => $status[$j],
'remark'=>$remark[$j],
'reasonDate'=>$reasonDate[$j],
'message'=>$message[$j],
'reasonAmt'=>$reasonAmt[$j],
'reason'=>$reason[$j]
);
print_r($data);
$save = array(
'b_orderno' =>$data['row']['order'],
'b_partner' => $data['row']['partner'],
'b_filestatus' => $data['row']['status'],
'b_remark' => $data['row']['remark'],
'b_date' => $data['row']['reasonDate'],
'b_amt' => $data['row']['reasonAmt'],
'b_reason' => $data['row']['reason']
);
$afterxss=$this->security->xss_clean($save);
if ($afterxss)
{
$this->db->insert('tbl_bankdata',$afterxss);
$response['error'] = "true";
$response['msg'] = "Process Partner added successfully";
}else{
$response['error'] = "false";
$response['msg'] = "Sometning wrong! please check the internet connection and try again";
}
}
echo json_encode($response);
}
Can any one help me out with this issue?
来源:https://stackoverflow.com/questions/56868489/message-uninitialized-string-offset-0-while-inserting-dynamic-input-field-data