Jump to content

Search the Community

Showing results for tags 'php mysql bug'.

  • Search By Tags

    Type tags separated by commas.
  • Search By Author

Content Type


  • Welcome to PHP Freaks
    • Announcements
    • Introductions
  • PHP Coding
    • PHP Coding Help
    • Regex Help
    • Third Party Scripts
    • FAQ/Code Snippet Repository
  • SQL / Database
    • MySQL Help
    • PostgreSQL
    • Microsoft SQL - MSSQL
    • Other RDBMS and SQL dialects
  • Client Side
    • HTML Help
    • CSS Help
    • Javascript Help
    • Other
  • Applications and Frameworks
    • Applications
    • Frameworks
    • Other Libraries
  • Web Server Administration
    • PHP Installation and Configuration
    • Linux
    • Apache HTTP Server
    • Microsoft IIS
    • Other Web Server Software
  • Other
    • Application Design
    • Other Programming Languages
    • Editor Help (Dreamweaver, Zend, etc)
    • Website Critique
    • Beta Test Your Stuff!
  • Freelance, Contracts, Employment, etc.
    • Services Offered
    • Job Offerings
  • General Discussion
    • PHPFreaks.com Website Feedback
    • Miscellaneous

Find results in...

Find results that contain...

Date Created

  • Start


Last Updated

  • Start


Filter by number of...


  • Start





Website URL








Donation Link

Found 1 result

  1. Hi guys, i'm developing a simple shopping cart for a website. Everythings worked great, until i decided to make a mod in order to switch type of article token from db. Now here's the bug: every time i try to delete an item from cart, it deletes every item but the first one in the cart. Even if the quantity is more than 1... Please, help me to find this bug.. it's about 4 days that i try to solve it. Sorry for my bad english, and thank you for your help. You can't find the website here and check the bug -> http://www.pizzainncasa.com/SitoGennaio/Sito/ordinaonline.php?&request=Pizza This is my code: ordinaonline.php (shoponline.php in english) <?php session_start(); include_once("config.php"); $request = $_GET['request']; ?> ||HTML.............|| <h1>Articoli </h1><hr><h4>Seleziona una categoria dal menù in alto per visualizzare i prodotti!</h4><br><br> <div class="products"> <?php //current URL of the Page. cart_update.php redirects back to this URL $current_url = base64_encode($url="http://".$_SERVER['HTTP_HOST'].$_SERVER['REQUEST_URI']); $results = $mysqli->query("SELECT * FROM Articoli WHERE Tipo = '$request' ORDER BY ID ASC"); if ($results) { //risultati dal db while($obj = $results->fetch_object()) { echo '<div class="product">'; echo '<form method="post" action="cart_update.php">'; //<img src="images/'.$obj->product_img_name.'" ></div>'; if($obj->product_img_name!=""){echo '<div class="product-thumb"><img width="200" height="100" src="images/'.$obj->product_img_name.'" ></div>';} echo '<div class="product-content"><h4>'.$obj->Nome.'</h4>'; echo '<div class="product-info">Prezzo '.$currency.$obj->Prezzo.' <button class="add_to_cart">Aggiungi al carrello</button></div>'; echo '</div>'; echo '<input type="hidden" name="product_code" value="'.$obj->ID.'" />'; echo '<input type="hidden" name="type" value="add" />'; echo '<input type="hidden" name="return_url" value="'.$current_url.'" />'; echo '</form>'; echo '</div>'; } } ?> </div> <div class="shopping-cart"> <h2>Il tuo carrello</h2> <?php if(isset($_SESSION["products"])) { $total = 0; echo '<ol>'; foreach ($_SESSION["products"] as $cart_itm) { echo ("removing ".$_SESSION['removing']); echo '<li class="cart-itm">'; echo '<span class="remove-itm"><a href="cart_update.php?removep='.$cart_itm["code"].'&return_url='.$current_url.'">×</a></span>'; echo '<h3>'.$cart_itm["name"].'</h3>'; echo $cart_itm['code']; echo ('added -> '.$_SESSION['test']); echo '<div class="p-qty">Quantita : '.$cart_itm["qty"].'</div>'; echo '<div class="p-price">Prezzo € :' .$cart_itm["price"].'</div>'; echo '</li>'; $subtotal = ($cart_itm["price"]*$cart_itm["qty"]); $total = ($total + $subtotal); } echo '</ol>'; echo '<span class="check-out-txt"><strong>Totale € : '.$total.'</strong> <a href="view_cart.php">Invia l\'ordine!</a></span>'; }else{ echo 'Il tuo carrello è vuoto'; } ?> </div> </div> [html............] and this is the cart_update.php [php]<?php session_start(); include_once("config.php"); //aggiunge un articolo al carrello if(isset($_POST["type"]) && $_POST["type"]=='add') { $product_code = filter_var($_POST["product_code"], FILTER_SANITIZE_STRING); //salva il product code $return_url = base64_decode($_POST["return_url"]); // salva il return url $_SESSION['test'] = $product_code; //MySqli query - prende le informazioni sull'oggetto dal db utilizzando il product_code $results = $mysqli->query("SELECT Nome,Prezzo FROM Articoli WHERE ID='$product_code' LIMIT 1"); $obj = $results->fetch_object(); if ($results) { //abbiamo le informazioni sugli articoli //prepara l'array per la sessione $new_product = array(array('name'=>$obj->Nome, 'code'=>$product_code, 'qty'=>1, 'price'=>$obj->Prezzo)); if(isset($_SESSION["products"])) //se la sessione esiste { $found = false; //setta found a false foreach ($_SESSION["products"] as $cart_itm) //scorre tutto l'array della sessione { if($cart_itm["code"] == $product_code){ //allora l'articolo è nell'array della sessione $qty = $cart_itm["qty"]+1; //aumenta la quantità dell'articolo $product[] = array('name'=>$cart_itm["name"], 'code'=>$cart_itm["code"], 'qty'=>$qty, 'price'=>$cart_itm["price"]); $found = true; }else{ //l'articolo non esiste, prendi le info vecchie e prepara l'array per la sessione $product[] = array('name'=>$cart_itm["name"], 'code'=>$cart_itm["code"], 'qty'=>$cart_itm["qty"], 'price'=>$cart_itm["price"]); } } if($found == false) //allora non abbiamo trovato l'articolo nell'array della sessione { //aggiungi un nuovo articolo nell'array della sessione $_SESSION["products"] = array_merge($product, $new_product); }else{ //abbiamo trovato l'articolo e abbiamo aumentato la quantità $_SESSION["products"] = $product; } }else{ //crea una nuova variabile sessione se non esiste $_SESSION["products"] = $new_product; } } //ritorna indietro alla pagina iniziale header('Location:'.$return_url); } //rimuovi un articolo dallo shopping cart if(isset($_GET["removep"]) && isset($_GET["return_url"]) && isset($_SESSION["products"])) { $product_code = $_GET["removep"]; //ottieni il codice prodotto dell'articolo da rimuovere $return_url = base64_decode($_GET["return_url"]); //ottieni l'url di ritorno foreach ($_SESSION["products"] as $cart_itm) //scorre tutto l'array della sessione { if($cart_itm["code"]==$product_code) //forse l'errore è qui { //allora l'articolo è nell'array della sessione $_SESSION['removing']=$cart_itm["code"]." ".$product_code; //continua solo se la quantità è >1 //rimuovendo quello che ha quantità 0 if($cart_itm['qty']>1) { $cart_itm['qty']-=1; } }else{ $product[] = array('name'=>$cart_itm["name"], 'code'=>$cart_itm["code"], 'qty'=>$cart_itm["qty"], 'price'=>$cart_itm["price"]); } //setta la sessione con i valori nuovi ----> PROBABILE ERRORE IN QUESTA SEZIONE <------ $_SESSION["products"] = $product; $product= array(); } //ritorna indietro header('Location:'.$return_url); } ?>
  • Create New...

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.