Results 1 to 2 of 2

Thread: PHP Dillema

  1. #1

    Thread Starter
    Junior Member
    Join Date
    Aug 2001
    Posts
    28

    PHP Dillema

    First of all, here is my code:

    PHP Code:
    <?php
    if (!isset($quantity) OR $quantity == "0"){
        die(
    "<body bgcolor='FF0000'><font face=verdana color='FFFFFF'>You have no items in your shopping cart.");
    }
    if (!isset(
    $cookie_cart)){
        
    $cookie_cart = array();
    }

    $string $quantity "x " $size " " $item;

    $cookie_cart[] = $string;

    setcookie("cookie_cart"$cookie_carttime()+600);

    print 
    "<body bgcolor='FF0000'>\n<font face='verdana' color='FFFFFF'>";

    for (
    $i 0$i count($cookie_cart); $i++) {
        print 
    "$cookie_cart[$i] <a href='order_bottom.php?request=remove&rid=$i'>";
        print 
    "<img src='images/-.gif' border=0 height=20 width=20></a><br>";
    }

    ?>
    I get an error where the code reads "$cookie_cart[] ...". The error reads as follows: " Fatal error: [] operator not supported for strings ". This of course makes no sense to me. $cookie_cart is not a string, it is an array. The first time this script loads it is initialized as an array, and then set as a cookie. I have been puzzling over this for a while and have no idea where the error is! Please help!

    Thanks

  2. #2
    scoutt
    Guest
    try $cookie_cart[0] = $string

    what you did was tell php that cookie_cart was an array twice. you said it once here

    $cookie_cart = array();
    then in that line I just showed you. since you already signed it an array you have to tell it where to place it in that array. the index value if you will.

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •  



Click Here to Expand Forum to Full Width