Note that there are some explanatory texts on larger screens.

plurals
  1. POPHP Array insert into MySQL table as individual rows.
    primarykey
    data
    text
    <p>I want to insert mutiple rows in mysql table using php. Data is in arrays and I am trying to employ following codes but its not working. Please help me.</p> <p>Query String is: </p> <pre><code>new_document.php?doctype=Inv&amp;paytype=u&amp;docno=3&amp;bookno=31&amp;prname=40329&amp;pename=1001&amp;paydate=07%2F22%2F2011&amp;indate=7%2F30%2F2011&amp;accname1=Man+Site&amp;DrAmount1=20&amp;CrAmount1=1&amp;accname2=Man+Site&amp;DrAmount2=0&amp;CrAmount2=5&amp;ref=Jul%2F2011 </code></pre> <p></p> <pre><code> $rows = explode("&amp;", $_SERVER['QUERY_STRING']); $rowcount =((count($rows)-9)/3); // Count set of rows received , 9 is the costant no of inputs $serialno = array(); $acc_name = array(); $debit = array(); $credit = array(); $serialno [] = $i; array_unshift($serialno,""); unset($serialno[0]); $acc_name[] = ($_GET['accname'.$i]); array_unshift($acc_name,""); unset($acc_name[0]); $debit[] = ($_GET['DrAmount'.$i]); array_unshift($debit,""); unset($debit[0]); $credit[] = ($_GET['CrAmount'.$i]); array_unshift($credit,""); unset($credit[0]); echo 'Serial Numbers : '.print_r($serialno); echo '&lt;br&gt;A/C Names : '.print_r($acc_name); echo '&lt;br&gt;Debit Amount : '.print_r($debit); echo '&lt;br&gt;Credit Amount : '.print_r($credit); This gives me following result : ARRAY ( [1] =&gt; 1 [2] =&gt; 2 ) SERIAL NUMBERS : 1ARRAY ( [1] =&gt; MAN SITE [2] =&gt; MAN SITE ) A/C NAMES : 1ARRAY ( [1] =&gt; 20 [2] =&gt; 0 ) DEBIT AMOUNT : 1ARRAY ( [1] =&gt; 1 [2] =&gt; 5 ) CREDIT AMOUNT : 1 for ($i=1;$i=$rowcount;$i++) { $amount = ($debit[$i]-$credit[$i]); $accname=$acc_name[$i]; $insert2 = "INSERT INTO `khata2`.`docitems` ( `dateinput`, `docno`, `itemno`, `accountname`, `amount`, `picrefno`, `updatestamp`) VALUES ( NOW(''), '$docno', '$i', '$accname', '$amount', '$docno', Null)"; } if (!mysql_query($insert2)){ echo '&lt;br&gt;&lt;a style="color:RED"&gt;Zero&lt;/a&gt; items saved! Try Again..&lt;br&gt;'; die('Error: ' . mysql_error()); break; } echo '&lt;br&gt;&lt;a style="color:GREEN"&gt;'.$rowcount.' &lt;/a&gt;record inserted.'; exit(); RESULTS AS : Fatal error: Maximum execution time of 30 seconds exceeded in F:\server\htdocs\xampp\Khata2\processor\new_document.php on line 184 ( Line 184 is '$amount',) </code></pre>
    singulars
    1. This table or related slice is empty.
    plurals
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. This table or related slice is empty.
 

Querying!

 
Guidance

SQuiL has stopped working due to an internal error.

If you are curious you may find further information in the browser console, which is accessible through the devtools (F12).

Reload