![]() |
Problems with setting up basket Cookie
Apologies in advance as I am a noob to PHP and progaming more generally.
Ok, I have a setcookie.php script which is set to include on other scripts, which goes as follows: Code:
<?phpCode:
<?phpCode:
<?phpCode:
<?phpAt this point I am looking to retrieve the value of [jumpinjakes][basket] cookie and assign it to a variable and echo it. So far my attempts have not worked. I also want to append the 'alb' value to the 'basket' cookie should the cookie already contain values so that the basket contents isn't overwritten all the time. My thoughts were: Code:
<?phpAny help would be very apprecicated - Thanks! |
session_start() is not required for cookies. Although this said you really should be using sessions instead of cookies anyway - cookies are extremely unreliable and under the full control of the user (who of course can not be trusted).
In fact, convert this to sessions, as its a lot easier to deal with than cookies. PHP Code:
PHP Code:
PHP Code:
|
That's wonderful Fou Lu. Thank you so much! It works!
To display a basket I have done this code. I am trying to create a running total of the cost of the items in the basket by assigning the price value to a global float variable. What I've done isn't correctly totalling, could anyone suggest what I've done wrong here? many thanks! Code:
<?php |
Create another session variable that keeps track of the total ... as they add
and remove items. That would be much more efficient than a query each time. You say "global" ... not sure what you mean by that. If you mean PHP "register_globals" ... that should be DISABLED (OFF). Usually, "off" is the server's default setting. There should be no ability to pass variables globally between scripts. period. . |
Sorry, I'm not sure I fully understand.
I have included a global variable in the script because I thought that without doing that the variable $price may be out of scope after the brackets, which of course may be wrong. The value contained within $row[2], once converted to a float would represent the cost of the item. Is this statement within the while loop, wrong for producing the running total? Code:
?php |
oh ... I thought you meant that you use the $price variable in all of your scripts.
That you update it with one script and read it / display it with another. What happens when you change this: $price=(float)$row[2];// converts to float $price=$price + $price; GLOBAL $price;//global To this: $price=$price + $row[2]; $price=number_format($price, 2, '.', ''); I don't know what the float part is all about, nor the GLOBAL part. What is that supposed to do for you? . |
| All times are GMT +1. The time now is 11:00 AM. |
Powered by vBulletin®
Copyright ©2000 - 2013, Jelsoft Enterprises Ltd.