Jump to content

Archived

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

masterchiller

**SOLVED** Putting an array in database

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 ?

Share this post


Link to post
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]

Share this post


Link to post
Share on other sites
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 ;).

Share this post


Link to post
Share on other sites

×

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.