I'm trying to build a shopping cart by adding the products to the database table "shopping cart" and then get them moved to table "orders". I was told I should make an array of the rows in the shopping cart table to and then loop the INSERT
query to put them in the orders table, but can someone explain how? I also read something about "implode" but I'm not really getting that either.
if(isset($_POST['button']))
{
$query = "SELECT * from members WHERE username='$username'";
while(list($id, $username, $password, $voornaam, $tussenvoegsel, $achternaam, $adres, $postcode, $telefoonnummer) = mysql_fetch_row($resultaat))
{
$adres=$adres2;
$postcode=$postcode2;
$query="SELECT * from winkelwagen WHERE username='$username'";
while(list($username, $diernr, $dier, $aantal, $prijs) = mysql_fetch_row($resultaat))
$query = "INSERT INTO bestelling (username, leveradres, postcode, dier, aantal)
VALUES ('$username', '$adres', '$postcode', '$dier', '$aantal')";
}
}
Well, it could be done simplier with a more complex INSERT
statement:
if(isset($_POST['button']))
{
$query = "INSERT INTO bestelling (username, leveradres, postcode, dier, aantal) ".
" SELECT username, adress, postcode, dier, aantval ".
" FROM winkelwagen ".
" WHERE user_name=? ";
$stmt = $mysqli->prepare($query);
$stmt->bind_param("s",$username);
$stmt->execute();
}
Make sure $mysqli
containis a valid mysqli
database connection
I'm sorry I don't know dutch (is it dutch?), so I'¡m not sure I picked up the correct table and field names.... but I hope you get the idea