I could take a guess. I would imagine that you are not closing all of your
browser windows. This means that the session cookie was being kept.

First I recommend using session_destroy(); at the end of your session work.

Also writting your script as if register globals was off would probably fix
it. e.g. use $_SESSION['qty'] instead of $qty for session data. Using
scripts ensures greater compatibilty and (hopefully) better security.

For more info on Register Globals you should check out these pages:
http://www.php.net/manual/en/security.registerglobals.php

http://www.php.net/manual/en/language.variables.predefined.php

I also suggest buying a book for PHP(if you don't have one) I would
recommend PHP and MySQL Web Development by Luke Welling and Laura Thopson.

It includes a working example of what you are probably trying to do.


--
JJ Harrison
[EMAIL PROTECTED]
www.tececo.com


"Wee Keat" <[EMAIL PROTECTED]> wrote in message
008601c236bc$a656e7a0$6300a8c0@wickid">news:008601c236bc$a656e7a0$6300a8c0@wickid...


Hi all,

I have been working on an online shopping thingy for quite a while and I
have encounter a strange problem which could not be solved. Deeply needed
your help.

Problem:

Its very hard to explain this. So, if you do not quite understand it, please
tell me, I will send some screenshots to you personally... I tried send it
here but it was rejected.

Okay.. here goes... I have a product list, where customers can select which
products to buy and enter the quantity they want...

Upon clicking on "Order" button, the customer is brought to his shopping
cartwhere there is the product, with price in "Per Unit", "Qty", and "Total
Price" . In this area, value for "Qty" column is obtained from the $qty that
is passed on from the previous page, where it is also a registered in
session_register("qty"). (The same goes to the Product, where prod_id is
obtained from $prod_id, also a session registered variable.)

It worked out fine so far... it could get the product, unit price, qty and
the total price.

But then, when I continued shopping second time, doing the same thing, first
select the product, then enter the quantity and then dump it in the shopping
cart, something starts going wrong... the "Qty" column do not show any value
at all......

However, products are still working... which means that the $prod_id session
is recorded. How come?


Here is the snippet of the script:
(took out the HTML <font> tags to make it more readable)

The code I used to create the table in the product list
----------------------------------------------------------------------------
---------------------------------

<?php
session_start();
session_register("qty");
?>


.... all other normal thingy......


while($query_data = mysql_fetch_array($result)) {

    $price = $query_data["price_lq"] * $rrp * $gst;
    $RowColor = useColor();

    echo "<TR BGCOLOR=\"$RowColor\">";
    echo "<TD>".$query_data["prod_brand"]."</TD>";
    echo "<TD>".$query_data["prod_code"]."</TD>";
    echo "<TD>".$query_data["prod_desc"]."</TD>";
    echo "<TD>$",number_format($price, 2, '.', ''),"</TD>";
    echo "<TD><input name=\"qty[".$query_data["prod_id"]."]\" type=\"text\"
size=\"1\"></TD>\n";
    echo "<TD><input type=\"checkbox\" name=\"choice[",
$query_data["prod_id"], "]\" value=\"", $query_data["prod_id"],"\"></TD>\n";

  }

all other html stuffs.............

----------------------------------------------------------------------------
-------------------------------------------



This is the code I used for the shopping cart
----------------------------------------------------------------------------
-------------------


<?php
session_start();
session_register("qty");
?>


.... all other normal thingy......


while (list($key,$prod_id) = each($cart)) {
   $result = mysql_query("SELECT * FROM products WHERE prod_id = '$prod_id'
ORDER BY prod_brand ASC", $link_id);
   $query_data = mysql_fetch_array($result);
   $RowColor = useColor();
   $index = $query_data["prod_id"];
   $quantity = $qty[$index];
   $price_perunit = $query_data["price_lq"] * $rrp * $gst;
   $total_price = $query_data["price_lq"] * $rrp * $gst * $quantity;
   $grandtotal = $grandtotal + $total_price;

   echo "<TR BGCOLOR=\"$RowColor\">";
   echo "<TD>".$query_data["prod_brand"]."</TD>";
   echo "<TD>".$query_data["prod_desc"]."</TD>";
   echo "<TD>$".number_format($price_perunit, 2, '.', '')."</TD>";
   echo "<TD>".$quantity."</TD>";
   echo "<TD>$".number_format($total_price, 2, '.',
'')."</strong><BR></FONT>&nbsp;&nbsp;</TD>\n";
   echo "\t<TD><a href=\"delete.php?delete=".$query_data["prod_id"]."\"
Onclick=\"return confirm('Are you sure?');\">";
   echo "[Delete]</a></TD></TR>";

  }

other html stuffs.................

----------------------------------------------------------------------------
----------------------------------------------




-- 
PHP General Mailing List (http://www.php.net/)
To unsubscribe, visit: http://www.php.net/unsub.php

Reply via email to