Home » Php » Inserting data from several arrays into respective fields in mysql database

Inserting data from several arrays into respective fields in mysql database

Posted by: admin June 30, 2018 Leave a comment

Questions:

My code did work when I was using mysql, now upgrading to mysqli has introduced problems. I have several interger arrays of various length and I am using a for loop of 48 steps to insert the data into the fields of my database. What is happenning is my array that has only 4 elements is causing the whole database insert to stop after the 4 th loop. The process stops with a rejected URL request, which is my page presenting the insert commands.

My code:

$setcomm = array  (1201.30,16.30,3.22,7.98,0.95, 78.78, 54.12,1.45,3.09,62.44,36.95,269.64,
  239.59,6.15,4.57,.43,100.00,.8622,14640,    1.21,  1.55, 1.19,  1.16, 1, 0, 0, 0,  0, 0, 0, 0.2125 );//dec30 2014

 $qk = array (1,1,1,1);


$xmports = array ( 777, 32197, 2534, 2124, 4658, 8943, 9214, 7360, 24020, 14689, 566, 2310, 00.00 ,3780, 10812, 2448, 262, 11557, 11171, 5711, 12740, 26850,  26551, 1818, 2615, 00.00, 00.00);

for($k=0;$k<48;$k++)

{   

$sqli = ( " INSERT INTO $mr (comm, qrt, trade, gross, interest, coffer) VALUES ( $setcomm[$k], $qk[$k], $xmports[$k], $GDP[$k], $bratz[$k], $fiscal[$k] )  ");



$stone=mysqli_query($connect2, $sqli);

}
Answers: