SitePoint Sponsor

User Tag List

Results 1 to 5 of 5
  1. #1
    SitePoint Enthusiast
    Join Date
    Jul 2005
    Posts
    59
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)

    Question Cookie Variable Problems...

    Hi

    Scenario:
    I am building a system (much like how a shopping cart would work) where someone requests information about a particular company which we then get sent an email of there chosen companies and we then send then manually send them back details of each one. they select what companies they would like to know about by clicking a button "add to cart" and each button would contain a different alue so we can tell which company is which.

    The Problem:
    We will be storing sessions via a cookie using php.

    The problem we are facing is how do we write each company requested to the cookie?? - We could assign variables on each button called $company_name - but then have diffeent values on each like Macdonalds, burgerKing etc.

    So if a person chooses say 3 companys we want to store it like this - how can we do that?

    $company_name (this would be macdonalds)
    $company_name (this would be BK)
    $company_name (this would be KFC)

    Conclusion:
    After we can successfully write to the cookie - they can then goto the checkout page and then get all the companies they requested i.e $company_name - shown in a list and then we will be emailed that (the emailing part i can handle)

    Please please please - can someone show me how to write multiple entries with the same variable (but different value) to a cookie.

    Thank you very much

  2. #2
    SitePoint Wizard stereofrog's Avatar
    Join Date
    Apr 2004
    Location
    germany
    Posts
    4,324
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    I am not sure I understood you fully, but generaly all data you need "later" goes to $_SESSION array, not in cookies.

  3. #3
    SitePoint Enthusiast
    Join Date
    Jul 2005
    Posts
    59
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    im not sure what you mean by the session quote? - im not using a database

    Perhaps you could explain a bit more please about how I would need it later??...

    What I waat is to be able to store all the companies they requested in the cookie (so they can surf the site in between and come back at a later stage to checout)

    How do I save the variable $company_name to a cookie? and how can I have multiple $company_name if they choose more than 1 company??? without overwritting the previous choice so they stack i.e.

    $company_name
    $company_name
    $company_name

    Each one of those variables has a different value but the sam evariable name - so it makes it easier.

  4. #4
    SitePoint Wizard stereofrog's Avatar
    Join Date
    Apr 2004
    Location
    germany
    Posts
    4,324
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    What I meant is
    PHP Code:
    session_start();
    $_SESSION['company_name'][] = $_REQUEST['company_name']; 
    wherever you need to save company_name given by user

    and
    PHP Code:
    session_start();
    $collected_names $_SESSION['company_name'
    wherever you need to manipulate collected names (e.g. on the checkout page).

  5. #5
    SitePoint Enthusiast
    Join Date
    Jul 2005
    Posts
    59
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    Thank you for your quick reply.

    May I ask - will this code work if a person was to choose 20 companies?

    Also would you have any advice as to differentiate between what companies where added i.e - what code string / link do I add to each "Add to basket" button - as they will all have the variable $company_name - how do i add a different value to each?

    As you can tell i'm quite new to this - so any help would be greatly recieved, as I heard this was the best place to go.

    Thank you


Bookmarks

Posting Permissions

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