I am a begginer in php. I am working for a school project and have come into a problem. I am guessing that it is simple but i can’t find it. My webstore saves the order in an array on a session. Here is the insert for the products that are bought.
foreach($_SESSION[“shopping_cart”] as $keys => $values)
{
$INSERT2 = “INSERT Into bestilling_has_vare (bestilling_bestilling_id, vare_vare_id, vare_varenavn, kvantum) values(’$last_id’, ‘2’, ‘{$values[“varenavn”]}’, ‘{$values[“kvantum”]}’)”;
mysqli_query($conn, $INSERT2);
}
Here i take the values from the session and insert them into a table. The only way i could get it to insert it propperly is to manyally put in the product id which is 2 (The second value in the insert). When i try to use for example $values[“product_id”], then it doesn’t work. When i echo the other values then they come out fine on the website, but when i do so with the product id then it is blank. I thought i could get the product id by selecting it with the product name, but i dont know how. Does anybody know how i can get the product id or fetch it with the product name?
If i am missing anything just say so and i will add more. I am using mysql as my database. In addition this is a school project so i don’t need to make it secure against sql injection.