Jump to content

**SOLVED** Putting an array in database


masterchiller

Recommended Posts

I'm using the following code;

[code]
<?php
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]

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

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]

Archived

This topic is now archived and is closed to further replies.

×
×
  • Create New...

Important Information

We have placed cookies on your device to help make this website better. You can adjust your cookie settings, otherwise we'll assume you're okay to continue.