php - Two for each loops for a query -


i trying make loop 2 arrays , run conflicts creates duplicate entries...i figure creating loop wrong.

        foreach($productids $productid){              foreach($qty $q) { $sql = "insert orderedproducts (productid, orderid, qty) values  ((select productid products productid ='$productid'), '$orderid', '$q')";            execute_query($sql);                   }            } 

if remove qty loop , hardcode qty in works fine. there sort of way combine 2 loops?

use insert into...select statement on this,

insert orderedproducts (productid, orderid, qty)  select productid, '$orderid', '$q'   products  productid = '$productid' 

as sidenote, query vulnerable sql injection if value(s) of variables came outside. please take @ article below learn how prevent it. using preparedstatements can rid of using single quotes around values.


Comments

Popular posts from this blog

php - Wordpress website dashboard page or post editor content is not showing but front end data is showing properly -

javascript - Get parameter of GET request -

javascript - Twitter Bootstrap - how to add some more margin between tooltip popup and element -