Solved

$_SESSION 1 Char Limit

Posted on 2008-10-20
3
343 Views
Last Modified: 2012-06-21
Hi,
I have a shopping cart that is added to by clicking on a link. If it's not in the cart already it adds it to a session array and sets the quantity to 1. If it is in the array already it adds 1 to the qunatity.

<?php
session_start();
$voucher = $_GET['voucher'];
if(isset($_SESSION['cart'][$voucher]))
{
   $_SESSION['cart'][$voucher]['qty']=$_SESSION['cart'][$voucher]['qty']+1;
}
else
{
   $_SESSION['cart'][$voucher]=$voucher;
   $_SESSION['cart'][$voucher]['qty']=1;
}
header("Location: giftlist.php?seq=".rand(1000,9999));
?>

Trouble is if they add more than 9 of the same item e.g. quantity is 9 then it goes back to 1. It's as if the array has a 1 int limit. I've tried setting it up using $_SESSION['cart'][$voucher]['qty']=999; but it just starts at 9.

Help please.
0
Comment
Question by:manfredfield
3 Comments
 
LVL 2

Accepted Solution

by:
JurgenvH earned 500 total points
ID: 22756532
Try something like this
<?php

session_start();

$voucher = $_GET['voucher'];

echo "Sent: ".$voucher."<br/>";

if(isset($_SESSION['cart'][$voucher]))

{

   $_SESSION['cart'][$voucher]['qty'] += 1;

}

else

{

   $_SESSION['cart'][$voucher]['name'] = $voucher;

   $_SESSION['cart'][$voucher]['qty'] = 1;

}

echo "After processing: ";

var_dump($_SESSION['cart']);

echo "<br/>";

?>

Open in new window

0
 
LVL 1

Author Closing Comment

by:manfredfield
ID: 31507762
works. great. thanks!!
0
 
LVL 19

Expert Comment

by:NerdsOfTech
ID: 22756768
Maybe this...
<?php

session_start();

$voucher = $_GET['voucher'];

if(isset($_SESSION['cart'][$voucher])){

 if(isset($_SESSION['cart'][$voucher]['qty']))

 {

    $_SESSION['cart'][$voucher]['qty']++;

 }

 else

 {

    $_SESSION['cart'][$voucher]['qty']=1;

 }

} 

else

{

  $_SESSION['cart'][$voucher]=$voucher;

  $_SESSION['cart'][$voucher]['qty']=1;

}

header("Location: giftlist.php?seq=".rand(1000,9999));

?>

Open in new window

0

Featured Post

Is Your Active Directory as Secure as You Think?

More than 75% of all records are compromised because of the loss or theft of a privileged credential. Experts have been exploring Active Directory infrastructure to identify key threats and establish best practices for keeping data safe. Attend this month’s webinar to learn more.

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

Developers of all skill levels should learn to use current best practices when developing websites. However many developers, new and old, fall into the trap of using deprecated features because this is what so many tutorials and books tell them to u…
Things That Drive Us Nuts Have you noticed the use of the reCaptcha feature at EE and other web sites?  It wants you to read and retype something that looks like this.Insanity!  It's not EE's fault - that's just the way reCaptcha works.  But it is …
The viewer will learn how to dynamically set the form action using jQuery.
The viewer will learn how to create and use a small PHP class to apply a watermark to an image. This video shows the viewer the setup for the PHP watermark as well as important coding language. Continue to Part 2 to learn the core code used in creat…

863 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question

Need Help in Real-Time?

Connect with top rated Experts

20 Experts available now in Live!

Get 1:1 Help Now