Home Php Mysql Insert Array in columns
Reply: 0

Php Mysql Insert Array in columns

user1356 Published in May 23, 2018, 7:18 am

I have the follow problem: I have differents arrays, each array contain a list of items. I try to insert in database but each item of list result togheter.

This is my code: (i use preg_replace for delete
between items)

$codice = preg_replace('/(<br>)+$/', '', $_POST['jcitemcodice']);
$prodotto = preg_replace('/(<br>)+$/', '', $_POST['jcitemname']);
$quantita = preg_replace('/(<br>)+$/', '', $_POST['jcitemqty']);
$prezzo = preg_replace('/(<br>)+$/', '', $_POST['jcitemprezzo']);

$a1 = array("$codice","$prodotto","$quantita","$prezzo");

$res = implode("','" ,$a1);

$sql = "INSERT INTO test (codice,prodotto,quantita,prezzo) VALUES ('$res')";

Making echo of query the result is:

INSERT INTO test (codice,prodotto,quantita,prezzo) VALUES ('SUT03M SUT02M','Arrabbiata Albahaca','12 6','1.25 1.3')

but for to be correct i need the result:

INSERT INTO test (codice,prodotto,quantita,prezzo) VALUES ('SUT03M','Arrabbiata','12','1.25'), VALUES ('SUT02M','Albahaca','6','1.3')

$codice contain: SUT03M SUT02M
$prodotto contain: Arrabbiata Albahaca
$quantita contain: 12 6
$prezzo contain: 1.25 1.3

I have try a lot of codes looking around but always same result.

Thanks you.

You need to login account before you can post.

About| Privacy statement| Terms of Service| Advertising| Contact us| Help| Sitemap|
Processed in 0.430075 second(s) , Gzip On .

© 2016 Powered by mzan.com design MATCHINFO