Page 1 of 1

Cart Cannot Update Accordingly

Posted: Wed Oct 17, 2007 5:54 am
by cyh123
scottayy | Please use

Code: Select all

,

Code: Select all

and [syntax="..."] tags where appropriate when posting code. Your post has been edited to reflect how we'd like it posted. Please read:  [url=http://forums.devnetwork.net/viewtopic.php?t=21171]Posting Code in the Forums[/url] to learn how to do it too.[/color]


Dear Mr/Ms

Below attached the script.

When i choose the "Save Changes" button the total item and total price will always reset to "0", cannot add up.  This problem also same when i change the quantity and press enter  +  press check out button. 

Need your kind & expertize advice.  Thank U so much.


show_cart.php

Code: Select all

<?php
  include ('book_sc_fns.php');
  // The shopping cart needs sessions, so start one
  session_start();

  @ $new = $_GET['new'];

  if($new)
  {
    //new item selected
    if(!isset($_SESSION['cart']))
    {
      $_SESSION['cart'] = array();
      $_SESSION['items'] = 0;
      $_SESSION['total_price'] ='0.00';
    }

    if(isset($_SESSION['cart'][$new]))
      $_SESSION['cart'][$new]++;
    else 
      $_SESSION['cart'][$new] = 1;

    $_SESSION['total_price'] = calculate_price($_SESSION['cart']);
    $_SESSION['items'] = calculate_items($_SESSION['cart']);
  }

  if(isset($_POST['save']))
  {   
    foreach ($_SESSION['cart'] as $isbn => $qty)
    {
      if($_POST[$isbn]=='0')
        unset($_SESSION['cart'][$isbn]);
      else 
        $_SESSION['cart'][$isbn] = $_POST[$isbn];
    }
    $_SESSION['total_price'] = calculate_price($_SESSION['cart']);
    $_SESSION['items'] = calculate_items($_SESSION['cart']);
  }

  do_html_header('Your shopping cart');

  if($_SESSION['cart']&&array_count_values($_SESSION['cart']))
    display_cart($_SESSION['cart']);
  else
  {
    echo '<p>There are no items in your cart</p>';
    echo '<hr />';
  }
  $target = 'index.php';

  // if we have just added an item to the cart, continue shopping in that category
  if($new)
  {
    $details =  get_book_details($new);
    if($details['catid'])    
      $target = 'show_cat.php?catid='.$details['catid']; 
  }
  display_button($target, 'continue-shopping', 'Continue Shopping');  

  // use this if SSL is set up
  // $path = $_SERVER['PHP_SELF'];
  // $server = $_SERVER['SERVER_NAME'];
  // $path = str_replace('show_cart.php', '', $path);
  // display_button('https://'.$server.$path.'checkout.php', 
  //                  'go-to-checkout', 'Go To Checkout');  

  // if no SSL use below code
  display_button('checkout.php', 'go-to-checkout', 'Go To Checkout');  

  
  do_html_footer();
?>

scottayy | Please use

Code: Select all

,

Code: Select all

and [syntax="..."] tags where appropriate when posting code. Your post has been edited to reflect how we'd like it posted. Please read:  [url=http://forums.devnetwork.net/viewtopic.php?t=21171]Posting Code in the Forums[/url] to learn how to do it too.[/color]

Posted: Wed Oct 17, 2007 7:33 am
by Josh1billion
Without taking your code itself into account, let me say this first as it may or may not be the solution:

Have you tried refreshing a few times?

I was writing a script in my game that allows users to trade items and gold and whatnot, and I was testing it on Internet Explorer, and whenever I would enter a number into the "gold" field and submit the form, it would always appear to go back to 0. I looked in at the data in phpMyAdmin and it was updated, but it just wasn't showing up in Internet Explorer correctly until I refreshed a few times. I then discovered that the problem was that the browser was displaying an old, cached version of the page rather than the updated page.

So that's one possibility, let us know if that's not it.

Cart Cannot Update Accordingly

Posted: Wed Oct 17, 2007 10:19 am
by cyh123
TQ for all the suggestion

Tried Refresh - still cannot update

any other suggestion???? Kindly advice

TQVM

Posted: Wed Oct 17, 2007 10:22 am
by John Cartwright
For starters, add the following to the top of your script

Code: Select all

ini_set('display_errors', true);
error_reporting(E_ALL);