skip to Main Content

I am trying to build a simple shopping cart using PHP and no Database.
Based on the user input, I search for an Item using ebay API(returns XML Data).
I am able to get its price,id,and other details.
I am then creating an array called ITEMS which contains all the data returned by ebay.
(I know I have to create a cart only for items that are selected).

The Issue is I am able to access the cart contents from the session within the search function but not from other functions.I am new to PHP could someone help me fix this.
As of now I am only trying to access the cart contents from buy.

function search(){
    $xml = new SimpleXMLElement($xmlstr);
        print "<table border=1>";
        $loop = $xml->categories[0]->category->items->product;
        foreach ( $loop as $dummy) {
            $id = $dummy->attributes();
            $link = $dummy->productOffersURL;
            $name = $dummy->name;
            $price = $dummy->minPrice;
            $image = $dummy->images->image->sourceURL;
                     }
                array_push($ITEMS, $item);
             }
}

I changed the for eeach loop and it worked:
The code is :

$id = (String) $dummy->attributes();
$link = (String)$dummy->productOffersURL;
$name = (String)$dummy->name;
$price = (String)$dummy->minPrice;

2

Answers


  1. Chosen as BEST ANSWER
    $id = (String) $dummy->attributes();
    $link = (String)$dummy->productOffersURL;
    $name = (String)$dummy->name;
    $price = (String)$dummy->minPrice;
    

  2. You shouldn’t call session start with the @ (error supression) modifier. It could be triggering and error and you wouldn’t know.

    Check if your php.ini configuration is set to autostart the session.

    session.auto_start = 0
    

    If it’s set to 1, you could be overwriting its contents by manually calling session start every time.

    Login or Signup to reply.
Please signup or login to give your own answer.
Back To Top
Search