Unable to insert to multiple table rows to oracle(10g) database using for loop PHP

43
January 12, 2019, at 09:50 AM

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.

Answer 1

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;
 }
READ ALSO
Custom queries using arrays and implode function in php

Custom queries using arrays and implode function in php

I am coding a game siteOn this site, every question should be displayed to the user only once

36
look for a tool to consume redis and virsialize the process

look for a tool to consume redis and virsialize the process

I am looking for a open source software to configure php scripts to consume redis list,and visualize the whole process and monitor the whole process

21
How to catch an exception for sodium_crypto_box

How to catch an exception for sodium_crypto_box

I am trying to see if the message gets corrupted in the middle I should be able to get an error but all I am seeing is a white page

7