foreach(($no_items as $key=>$txt ) && ($b_cost as $key=>$txt1 ))
{
$sql1 = "INSERT INTO bulk_s (`no_items`,`b_cost`) VALUES ('$txt[$key]','$txt1[$key]') ";
}
I have two dynamically created arrays in my php page whose values I need to store in the DB in the same row
my js code
function changeIt()
{
my_div.innerHTML = my_div.innerHTML +"<br> items <input type='text' name='txt[]'+ i>"
my_div.innerHTML = my_div.innerHTML +" cost <input type='text' name='txt1[]'+ j>"
i++;
j++;
}
Your
foreachsyntax isn’t valid PHP. If you want to iterate over two arrays with identical keys at the same time, you have to iterate over the keys instead:However, note that you should never construct SQL statements like this, it makes them liable to SQL injections. This is an inacceptable coding practice. In the best case it makes your program less elegant, in the worst case it opens you up to lawsuit, and there is a very simple superior solution.