Napisano: 28 Avg 2011 21:53
Pozdrav,ako može mala pomoć.Imam shopping cart i treba da ubacim porudžbinu u bazu kroz formu,npr,podaci korisnika + porudžbina a bilo bi dobro da tu istu porudžbinu dobijem i na mejl.
Nikako ne mogu da uhvatim total,tj. naziv,opis,cenu ,količinu..evo koda
tabela za porudžbinu ima
podaci kupca.......................
order_id
name
description
price
quantity
date
function.inc.php
<?php
function writeShoppingCart() {
$cart = $_SESSION['cart'];
if (!$cart) {
return '<p>You have no items in your shopping cart</p>';
} else {
// Parse the cart session variable
$items = explode(',',$cart);
$s = (count($items) > 1) ? 's':'';
return '<p>You have <a href="cart.php">'.count($items).' item'.$s.' in your shopping cart</a></p>';
}
}
function showCart() {
$total = "";
global $db;
$cart = $_SESSION['cart'];
if ($cart) {
$items = explode(',',$cart);
$contents = array();
foreach ($items as $item) {
$contents[$item] = (isset($contents[$item])) ? $contents[$item] + 1 : 1;
}
$output[] = '<div id = "container">';
$output[] = '<form action="cart.php?action=update" method="post" id="cart">';
$output[] = '<table>';
foreach ($contents as $id=>$qty) {
$sql = 'SELECT * FROM products WHERE id = '.$id;
$result = $db->query($sql);
$row = $result->fetch();
extract($row);
$output[] = '<tr>';
$output[] = '<td><a href="cart.php?action=delete&id='.$id.'" class="r">Remove</a></td>';
$output[] = '<td>'.$name.' by '.'</td>';
$output[] = '<td>£'.$price.'</td>';
$output[] = '<td>£'.$picture.'</td>';
$output[] = '<td><input type="text" name="qty'.$id.'" value="'.$qty.'" size="3" maxlength="3" /></td>';
$output[] = '<td>£'.($price * $qty).'</td>';
$total += $price * $qty;
$output[] = '</tr>';
}
$output[] = '</table>';
$output[] = '<p>Grand total: <strong>£'.$total.'</strong></p>';
$output[] = '<div><button type="submit">Update cart</button></div>';
$output[] = '</form>';
$output[] = '</div>';
} else {
$output[] = '<p>You shopping cart is empty.</p>';
}
return join('',$output);
}
?>
index.php
<?php
echo writeShoppingCart();
?>
<?php
$sql = 'SELECT * FROM products ORDER BY id';
$result = $db->query($sql);
$output[] = '<ul>';
while ($row = $result->fetch()) {
$output[] = '<li>"'.$row['name'].'" by '.$row['description'].': £'.$row['price'].$row['picture'].'<br /><a href="cart.php?action=add&id='.$row['id'].'">Add to cart</a></li>';
}
$output[] = '</ul>';
echo join('',$output);
?>
U formi sam probao sa promenljivima npr value="<?php echo $name ?>"
$description
$price itd itd ali ne dobijem to što mi treba.
Hvala unapred.
Dopuna: 29 Avg 2011 11:15
Možda nisam bio dovoljno jasan ,da pojasnim još malo.
Pored podataka o korisniku,sadržaj korpe treba da ubacim u bazu putem html forme.Nije mi problem da ubacim podatke o korisniku nego je problem da uhvatim sadržaj korpe.
korpa:
Pa,ako neko može da pomogne...
|