|
|
|
| |||||||||
![]() |
|
|
«
Previous Thread
|
Next Thread
»
|
Thread Tools | Search this Thread | Rate Thread | Display Modes |
|
|
|
Stay one step ahead of the competition. Evaluate and give feedback
on some of the hottest web development tools on the market today.
Make your opinion heard! Click
Here
|
|
#1
|
|||
|
|||
|
PHP 4.1.2 and arrays
Hello,
I'm having a problem getting an array to accept values. I'm using php 4.1.2 on and windows nt4 platform (not my choice). In previous versions of php I had no problems creating an array and adding items to the array everytime a user clicked on the "buy" button and the page reloaded adding the product_id to the array. Now it won't work at all!!! Here is the code I'm using. I also have set the array as a cookie as session variables did not seem to be working either. <?PHP session_start(); //checking to see if the cookie exists, if not creating the array if(!$cart) { $cart = array(); setCookie("cart", $cart, time()+ 7200); } //retrieving the product id passed into the page by clicking on the //buy button $product_id = $_GET['product_id']; - product id value is 9005 $total_products = count($cart); //making the total_products var a session var $_SESSION['total_products'] = $total_products; if(isset($product_id)) { $i = 1 + total_products; $cart[$i] = $product_id; $total_products = count($cart); } while(list($key, $val) = each ($cart)) { echo "key: $key - val: $val<br>"; } ?> When I check to see what the $cart var is: it says it's an array, but it won't list out the key or values of the array. When I use: echo $cart[$i] - the result is 9 not 9005 which is the product_id value. Could somebody please help me with this before I go crazy? Thanks, Trish |
|
#2
|
|||
|
|||
|
RE: PHP 4.1.2 and arrays
I dont know a lot about cookies I always work with sessions. But I cant see in your code somewhere you really put the value in your cookie. I can only see that you create a cookie (empty) but not when someone has selected an item. So i think you have to make something like
if($submit) { set your cookie here with the new value } Cya Bjorn Maby I am wrong but this is all I can see. |
|
#3
|
|||
|
|||
|
RE: PHP 4.1.2 and arrays
What kind of error message/warning do you get?
|
|
#4
|
|||
|
|||
|
RE: PHP 4.1.2 and arrays
u cant store arrays in cookies. use only sessions instead.
|
|
#5
|
|||
|
|||
|
RE: PHP 4.1.2 and arrays
And since you are using PHP 4.1.2 you are better off using the new super globals $_SESSION, $_COOKIE, $_GET, $_POST and $_FILES.
|
![]() |
| Viewing: Codewalkers Forums > PHP Related > PHP Coding > PHP 4.1.2 and arrays |
| Thread Tools | Search this Thread |
| Display Modes | Rate This Thread |
|
|
|
|
|
|
|