Unable to insert the multiple rows in the database while using the for loop, instead of inserting the multiple rows it will insert only the single row to the oracle DB.
After multiple time trying I'm unable to insert multiple rows in oracle database while using for loop(PHP), after spending a lot of time on search. I'm unable to find the solution of my problem. As far as I think there is some wrong with QUERY.
Moreover it will inserting the single row in the database,
My piece of code is given following
$arr =array();
for( $l=0; $l<count($_POST['i_id']); $l++ )
{
$item_id = $_POST['i_id'][$l];
$fk_saleord_no = $r;
$var2 = $_POST['sales_order_date'];
$fix2 = str_replace('/', '-', $var2);
$fk_saleord_date = date('d-m-Y', strtotime($fix2));
$entity_no_branch = $_POST['p_branch'];
$insert1 = "INSERT INTO SALE_ORDER_DTL(FK_SALEORD_NO, FK_SALEORD_DATE,
ENTITY_NO_BRANCH, ITEM_ID )VALUES('.$fk_saleord_no.','.
$fk_saleord_date.','. $entity_no_branch.','. $item_id .')";
$send1 = oci_parse($gerp, $insert1);
oci_execute($send1);
$arr[] = $insert1;
}
On printing the my loop:
echo "<pre>";
print_r($arr);
exit;
It gives the following result:
Array
(
[0] => INSERT INTO SALE_ORDER_DTL(FK_SALEORD_NO, FK_SALEORD_DATE,
ENTITY_NO_BRANCH, ITEM_ID )VALUES('.1190062.','. 11-01-2019.','. POS-
0001.','. 168 .')
[1] => INSERT INTO SALE_ORDER_DTL(FK_SALEORD_NO, FK_SALEORD_DATE,
ENTITY_NO_BRANCH, ITEM_ID )VALUES('.1190062.','. 11-01-2019.','. POS-
0001.','. 191 .')
[2] => INSERT INTO SALE_ORDER_DTL(FK_SALEORD_NO, FK_SALEORD_DATE,
ENTITY_NO_BRANCH, ITEM_ID )VALUES('.1190062.','. 11-01-2019.','. POS-
0001.','. 224 .')
)
All I want is to insert all the rows to the database.
There is no need to concatenate in your query
or use ".$fk_saleord_no." to call the parameter in query where you have used single ( ' ) use ( " )
$arr =array();
for( $l=0; $l<count($_POST['i_id']); $l++ )
{
$item_id = $_POST['i_id'][$l];
$fk_saleord_no = $r;
$var2 = $_POST['sales_order_date'];
$fix2 = str_replace('/', '-', $var2);
$fk_saleord_date = date('d-m-Y', strtotime($fix2));
$entity_no_branch = $_POST['p_branch'];
$insert1 = "INSERT INTO SALE_ORDER_DTL(FK_SALEORD_NO, FK_SALEORD_DATE,
ENTITY_NO_BRANCH, ITEM_ID )VALUES('$fk_saleord_no','
$fk_saleord_date','$entity_no_branch',' $item_id ')";
$send1 = oci_parse($gerp, $insert1);
oci_execute($send1);
$arr[] = $insert1;
}