Hello, php newbie calling...
I've been making this little shopping cart application that stores the products into senssion, now i've problem from getting them out. It only shows the last one in the array. The application should actually send the details via email, but now as I'm testing it i put it save the details into txt-file..
<?php
// Include MySQL class
require_once('inc/mysql.class.php');
// Include database connection
require_once('inc/global.inc.php');
// Include functions
require_once('inc/functions.inc.php');
// Start the session
session_start();
if(isset ($_GET['action'])){
$cart = $_SESSION['cart'];
if ($cart) {
$items = explode(',',$cart);
$contents = array();
foreach ($items as $item) {
$contents[$item] = (isset($contents[$item])) ? $contents[$item] + 1 : 1;
}
foreach ($contents as $tid=>$qty) {
$sql = 'SELECT * FROM tuotteet WHERE tid = '.$tid;
$result = $db->query($sql);
$row = $result->fetch();
extract($row);
$total += $hinta * $qty;
$product = $tuotenimi;
$nimi = $_POST['Nimi'];
$katuos = $_POST['Katuosoite'];
$postinro = $_POST['Postinro'];
$toimipaikka = $_POST['Toimipaikka'];
$puhnro = $_POST['Puhelinnro'];
$sapo = $_POST['Sahkoposti'];
$to = "mail@mail.com";
$subject = "Tilaus";
$from = "Dolphin verkkokauppa";
$myFile = "testFile.txt";
$fh = fopen($myFile, 'w') or die("can't open file");
$stringData = "Tilatut tuotteet: \n $product, kpl $qty \n Tilaus yhteensä $total euroa \n Tilaajan tiedot: \n Nimi: $nimi \n Osoite: $katuos, $postinro $toimipaikka \n Puhelinnro: $puhnro \n Email: $sapo";
fwrite($fh, $stringData);
fclose($fh);}
}
}
?>
I'd really appreciate the help.