Hi, I have a SESSION variable that contains this data (id, name, quantity, price) is a shopping cart, so when I bring this variable with all the content to my other page I do not know how to insert the amount that this array in the specific fields of my table which has these fields (Name, Address, Email, Phone, Taco_pastor, Taco_suadero, Torta_pastor, Torta_suadero, Refreshment, Juice, Total, Date) in that order, what I want is for me to insert the amount that the user has requested and that if I do not have an amount, I put it as zero in my table
I have tried with foreach and ifs to compare them by the value of the inputs (where they look good) but until now this does not work for me and only prints the amount in "Torta_suadero"
foreach($_SESSION['shopping_cart'] as $key => $product):
$cant=$_POST['nombre'];
if ($cant=='Taco_pastor') {
$tacop2= $product['quantity'];
} else {
$tacop2=0;
}
if ($cant=='Taco_suadero') {
$tacosu2= $product['quantity'];
} else {
$tacosu2=0;
}
if ($cant=='Torta_pastor') {
$tortap2= $product['quantity'];
} else {
$tortap2=0;
}
if ($cant=='Torta_suadero') {
$tortasu2= $product['quantity'];
} else {
$tortasu2=0;
}
if ($cant=='Refresco') {
$refresco2= $product['quantity'];
} else {
$refresco2=0;
}
if ($cant=='Jugo') {
$jugo2= $product['quantity'];
} else {
$jugo2=0;
}
endforeach;
if(!$error){
echo '';
$sql = "insert into pedidos(Nombre,Direccion,Email,Telefono, Taco_pastor,Taco_suadero,Torta_pastor,Torta_suadero,Jugo,Refresco,Total,Fecha)
values('$cliente', '$dir2', '$email2', '$tel2', '$tacop2','$tacosu2','$tortap2','$tortasu2','$jugo2','$refresco2','$total2','$fecha')";
if(mysqli_query($conn, $sql)){
$successMsg = 'SU PEDIDO A SIDO TOMADO EN UN MOMENTO LE LLEGARA A SU DOMICILIO GRACIAS!!!!';
}else{
echo 'Error '.mysqli_error($conn);
}
}