SunQuest
           PHP Coding
 
Forums: » Register « |  User CP |  Games |  Calendar |  Members |  FAQs |  Sitemap |  Support | 
User Name:
Password:
Remember me
Try It Free
Go Back   Codewalkers ForumsPHP RelatedPHP Coding

Reply
Add This Thread To:
  Del.icio.us   Digg   Google   Spurl   Blink   Furl   Simpy   Y! MyWeb 
Thread Tools Search this Thread Rate Thread Display Modes
 
Unread Codewalkers Forums Sponsor:
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  
Old September 19th, 2002, 05:37 AM
tkenney tkenney is offline
Codewalkers Newbie (0 - 499 posts)
 
Join Date: Apr 2007
Posts: 1 tkenney User rank is Just a Lowly Private (1 - 20 Reputation Level) 
Time spent in forums: < 1 sec
Reputation Power: 0
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


Reply With Quote
  #2  
Old September 19th, 2002, 08:15 AM
neutcomp neutcomp is offline
Codewalkers Newbie (0 - 499 posts)
 
Join Date: Apr 2007
Location: weesp, N-H, The Netherlands
Posts: 14 neutcomp User rank is Just a Lowly Private (1 - 20 Reputation Level) 
Time spent in forums: < 1 sec
Reputation Power: 0
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.

Reply With Quote
  #3  
Old September 19th, 2002, 08:37 AM
Kohaar Kohaar is offline
Codewalkers Newbie (0 - 499 posts)
 
Join Date: Apr 2007
Location: Denmark
Posts: 147 Kohaar User rank is Just a Lowly Private (1 - 20 Reputation Level) 
Time spent in forums: 4 m 37 sec
Reputation Power: 2
Send a message via ICQ to Kohaar
RE: PHP 4.1.2 and arrays

What kind of error message/warning do you get?

Reply With Quote
  #4  
Old September 20th, 2002, 02:40 AM
zombie zombie is offline
Codewalkers Intermediate (1500 - 1999 posts)
 
Join Date: Apr 2007
Location: serbia
Posts: 1,876 zombie User rank is Just a Lowly Private (1 - 20 Reputation Level) 
Time spent in forums: < 1 sec
Reputation Power: 3
RE: PHP 4.1.2 and arrays

u cant store arrays in cookies. use only sessions instead.

Reply With Quote
  #5  
Old September 21st, 2002, 03:15 PM
mld mld is offline
Contributing User
Codewalkers Newbie (0 - 499 posts)
 
Join Date: Apr 2007
Location: Stockholm, Sweden
Posts: 5 mld User rank is Just a Lowly Private (1 - 20 Reputation Level) 
Time spent in forums: 3 m
Reputation Power: 0
Send a message via ICQ to mld
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.

Reply With Quote
Reply

Viewing: Codewalkers ForumsPHP RelatedPHP Coding > PHP 4.1.2 and arrays


Thread Tools  Search this Thread 
Search this Thread:

Advanced Search
Display Modes  Rate This Thread 
Rate This Thread:


Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

vB code is On
Smilies are On
[IMG] code is On
HTML code is Off
View Your Warnings | New Posts | Latest News | Latest Threads | Shoutbox
Forum Jump


Forums: » Register « |  User CP |  Games |  Calendar |  Members |  FAQs |  Sitemap |  Support | 
  
 





© 2003-2008 by Developer Shed. All rights reserved. DS Cluster 5 hosted by Hostway