masterchiller Posted March 9, 2006 Share Posted March 9, 2006 I'm using the following code;[code]<?phpforeach ($_SESSION['ordered_articles'] AS $array){$articlenumber = $array['artnumber'];$articleamount = $array['amount'];}$mysql_query = "INSERT INTO `orders` values ('NULL', '$articlenumber', '$articleamount')";$result = mysql_query($mysql_query);?>[/code]This code puts the array in the database. But when I have more than one article in my array, it just ads one article in the database, instead of them all.What am I doing wrong here ? Link to comment https://forums.phpfreaks.com/topic/4565-solved-putting-an-array-in-database/ Share on other sites More sharing options...
Barand Posted March 9, 2006 Share Posted March 9, 2006 The mysql insert also needs to be inside the foreach loop[code]foreach ($_SESSION['ordered_articles'] AS $array){ $articlenumber = $array['artnumber']; $articleamount = $array['amount']; $mysql_query = "INSERT INTO `orders` values ('NULL', '$articlenumber', '$articleamount')"; $result = mysql_query($mysql_query);}[/code] Link to comment https://forums.phpfreaks.com/topic/4565-solved-putting-an-array-in-database/#findComment-15936 Share on other sites More sharing options...
masterchiller Posted March 9, 2006 Author Share Posted March 9, 2006 Thank you !! This really worked for me! =)I was looking for a while loop or something, but this is a much easier and better solution ;). Link to comment https://forums.phpfreaks.com/topic/4565-solved-putting-an-array-in-database/#findComment-15939 Share on other sites More sharing options...
Recommended Posts
Archived
This topic is now archived and is closed to further replies.