![]() |
![]() |
![]()
Post
#1
|
|
Grupa: Zarejestrowani Postów: 1 Pomógł: 0 Dołączył: 13.01.2012 Ostrzeżenie: (0%) ![]() ![]() |
Mam problem z zapisaniem składanego zamówienia ze strony www w bazie danych. Przesyłam kod i proszę, żeby ktoś mi pomógł go naprawić.
to jest cart.php <?php // Include MySQL class require_once('mysql.class.php'); // Include database connection require_once('global.inc.php'); // Include functions require_once('functions.inc.php'); // Start the session session_start(); // Process actions $cart = $_SESSION['cart']; $action = $_GET['action']; switch ($action) { case 'add': if ($cart) { $cart .= ','.$_GET['id']; } else { $cart = $_GET['id']; } break; case 'delete': if ($cart) { $items = explode(',',$cart); $newcart = ''; foreach ($items as $item) { if ($_GET['id'] != $item) { if ($newcart != '') { $newcart .= ','.$item; } else { $newcart = $item; } } } $cart = $newcart; } break; case 'update': if ($cart) { $newcart = ''; foreach ($_POST as $key=>$value) { if (stristr($key,'ilosc')) { $id = str_replace('ilosc','',$key); $items = ($newcart != '') ? explode(',',$newcart) : explode(',',$cart); $newcart = ''; foreach ($items as $item) { if ($id != $item) { if ($newcart != '') { $newcart .= ','.$item; } else { $newcart = $item; } } } for ($i=1;$i<=$value;$i++) { if ($newcart != '') { $newcart .= ','.$id; } else { $newcart = $id; } } } } } $cart = $newcart; break; case 'update': if ($cart) { $newcart = ''; foreach ($_POST as $key=>$value) { if (stristr($key,'ilosc')) { $id = str_replace('ilosc','',$key); $items = ($newcart != '') ? explode(',',$newcart) : explode(',',$cart); $newcart = ''; foreach ($items as $item) { if ($id != $item) { if ($newcart != '') { $newcart .= ','.$item; } else { $newcart = $item; } } } for ($i=1;$i<=$value;$i++) { if ($newcart != '') { $newcart .= ','.$id; } else { $newcart = $id; } } } } } $cart = $newcart; break; } $_SESSION['cart'] = $cart; ?><!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Strict//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-strict.dtd"> <html xmlns="http://www.w3.org/1999/xhtml" xml:lang="en" lang="en"> <head> <title>Karta zamowien</title> <link rel="stylesheet" href="css/styles.css" /> </head> <body> <div id="shoppingcart"> <h1>Twoja karta zamowien</h1> <?php echo writeShoppingCart(); ?> </div> <div id="contents"> <h1>Prosze sprawdz szczegoly zamowienia...</h1> <?php echo showCart(); ?> <p><a href="index.php">Powrot do sklepu...</a></p> </div> </body> </html> http://www.w3.org/TR/xhtml1/DTD/xhtml1-strict.dtd www.w3.org Udostępnij funtioncs.inc.php <?php function writeShoppingCart() { $cart = $_SESSION['cart']; if (!$cart) { return '<p>Nic jeszcze nie zamowiles</p>'; } else { // Parse the cart session variable $items = explode(',',$cart); $s = (count($items) > 1) ? 's':''; return '<p>Zamowiles lacznie <a href="cart.php">'.count($items).' ksiazek </a></p>'; } } function showCart() { 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[] = '<form action="cart.php?action=update" method= "POST" id="cart">'; $output[] = '<table>'; foreach ($contents as $id=>$ilosc) { $sql = 'SELECT * FROM ksiazki WHERE id_ksiazki = '.$id; //pobiera ksiazki ktore zamowilismy z BD $result = $db->query($sql); $row = $result->fetch(); extract($row); $output[] = '<tr>'; $output[] = '<td><a href="cart.php?action=delete&id='.$id.'" class="r">Usun</a></td>'; $output[] = '<td>tytul:'.$tytul.'</td>'; $output[] = '<td>cena/szt : '.$cena.'</td>'; $output[] = '<td><input type="text" name="qty'.$id.'" value="'.$ilosc.'" size="3" maxlength="3" /></td>'; $output[] = '<td>'.($cena * $ilosc).'zl</td>'; $total += $cena * $ilosc; $sql = 'SELECT * FROM rabat WHERE id_rabat = '.$id; //pobiera ksiazki ktore zamowilismy z BD $result = $db->query($sql); $row = $result->fetch(); extract($row); $output[] = '<td>rabat:'.$nazwa.'</td>'; $output[] = '</tr>'; } $output[] = '</table>'; $output[] = '<p>Do zaplaty: <strong>'.$total.' zl</strong></p>'; $output[] = '<div><button type="submit">Wyslij zamowienie</button></div>'; $output[] = '</form>'; } else { $output[] = '<p>Twoja karta zamowien jest pusta.</p>'; } return join('',$output); } ?> wydaje mi sie ze cos nie dziala w tych dwoch kawalkach dlatego nie chce tych danych z zamowienia zapisac do bazy danych (dokladnie do tabeli zamowienia) z functions.inc.php $output[] = '<form action="cart.php?action=update" method= "POST" id="cart">'; a z cart.php to bedzie $cart = $newcart; break; case 'update': if ($cart) { $newcart = ''; foreach ($_POST as $key=>$value) { if (stristr($key,'ilosc')) { $id = str_replace('ilosc','',$key); $items = ($newcart != '') ? explode(',',$newcart) : explode(',',$cart); $newcart = ''; foreach ($items as $item) { if ($id != $item) { if ($newcart != '') { $newcart .= ','.$item; } else { $newcart = $item; } } } for ($i=1;$i<=$value;$i++) { if ($newcart != '') { $newcart .= ','.$id; } else { $newcart = $id; } } } } } $cart = $newcart; break; |
|
|
![]() ![]() |
![]() |
Aktualny czas: 22.08.2025 - 14:44 |