I am currently using the following INSERT INTO :
$sql= "INSERT INTO orders (Orderdatum, Naam, Woonplaats, Straatnaam, Huisnummer, Telefoon, Aantal, Prijs)
VALUES (now(), '$_POST[naam]','$_POST[woonplaats]','$_POST[straatnaam]','$_POST[huisnummer]','$_POST[telefoonnummer]', '$total_number', '$total_price')
";
mysql_query($sql);
And:
foreach ($products as $key => $product){
$number = isset($_POST[$key])?$_POST[$key]:'';
if ($number > 0){
$sql2 = "INSERT INTO ordered_products (Ordernr, Product, Aantal) VALUES (last_insert_id(), '$product', '$number')";
mysql_query($sql2);
}
}
To place the customers order info in 1 table, and the products that are ordered in another. With the correct Ordernr.
This is working just as it should. But i was told the second piece of code the foreach
shouldn't be done like i have it right now.
Since it will give problems in the long run if I add more values and make bigger arrays.
So i'm wondering what is the correct way of using this foreach
?
Dont get me wrong, my code is working as it should, no problems. But i was told this isn't the right way