1

I am inserting multiple records into mysql with the codes below. However, after inserting into mysql, I need to insert same into pervasive sql for use by pastel. I use odbc_exec which works well if record to be inserted is jus one. I need help pls.

$query .= '
   INSERT INTO supplier_invoice
        (inv_number, SupplCode, Item_No, product_name, 
         qty, unitPrice, subtotal, inv_dt, created_by) 
   VALUES("'.$inv_No.'", "'.$supp_code.'", "'.$itNo.'", "'.$itName.'", 
          "'.$qqty.'", "'.$cost.'", "'.$ttotal.'", "'.$inv_dt.'", 
          "'.$submitted_by.'"); 
   ';
RiggsFolly
  • 93,638
  • 21
  • 103
  • 149
  • I assume by the use of **`$query .=`** you create more than one insert in the `$query` variable and then try and execute those queries all in one go? – RiggsFolly Jan 31 '18 at 13:28
  • It might have been helpful if you showed us the database access code as well as a simple loading of a string variable – RiggsFolly Jan 31 '18 at 13:30
  • 1
    Which by the way is wide open to [SQL Injection Attack](http://stackoverflow.com/questions/60174/how-can-i-prevent-sql-injection-in-php) Even [if you are escaping inputs, its not safe!](http://stackoverflow.com/questions/5741187/sql-injection-that-gets-around-mysql-real-escape-string) Use [prepared parameterized statements](http://php.net/manual/en/mysqli.quickstart.prepared-statements.php) – RiggsFolly Jan 31 '18 at 13:30
  • @RiggsFolly Ok I will – Kwasi Owusu Jan 31 '18 at 13:32

1 Answers1

0

You shoud use other way to consider query:

At start:

$query = 'INSERT INTO supplier_invoice
        (inv_number, SupplCode, Item_No, product_name, 
         qty, unitPrice, subtotal, inv_dt, created_by) 
   VALUES ';
$first_query = true;

In the loop:

if ($first_query) {
    $first_query = false;
} else {
    $quetry .= ',';
}
$query .= '("'.$inv_No.'", "'.$supp_code.'", "'.$itNo.'", "'.$itName.'", 
      "'.$qqty.'", "'.$cost.'", "'.$ttotal.'", "'.$inv_dt.'", 
      "'.$submitted_by.'")';
Vladimir
  • 1,373
  • 8
  • 12