I'm getting 2 fields from my html form which store the value in an Array.
$ingredients = $_POST['ingredients'];
$quantity = $_POST['quantity'];
I want to insert these 2 value to my mysql db. So I'm using following:
foreach($ingredients as $in)
{
foreach($quantity as $q)
{
echo "Intredent and quantity is : $in and $q<br/>";
//$insert = my mysql Insert query;
}
}
But it showing twice value. For ex: if it's 2 value it's showing 4 value.. etc.
foreach($ingredients as $key => $in)
{
echo "Intredent and quantity is : $in and $_POST['quantity'][$key]<br/>";
}
Are you trying to do that? Each ingredient with the quantity amount?
try this
$ingredients = $_POST['ingredients'];
$quantity = $_POST['quantity'];
$arr_count = sizeof($ingredients);
for($i=0; $i<$arr_count; $i++)
{
$in = $ingredients[$i];
$q = $quantity[$i];
echo "Intredent and quantity is : $in and $q<br/>";
//$insert = my mysql Insert query;
}
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With