Solved

$_SESSION 1 Char Limit

Posted on 2008-10-20
3
355 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
[X]
Welcome to Experts Exchange

Add your voice to the tech community where 5M+ people just like you are talking about what matters.

  • Help others & share knowledge
  • Earn cash & points
  • Learn & ask questions
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

Independent Software Vendors: We Want Your Opinion

We value your feedback.

Take our survey and automatically be enter to win anyone of the following:
Yeti Cooler, Amazon eGift Card, and Movie eGift Card!

Question has a verified solution.

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

Suggested Solutions

Deprecated and Headed for the Dustbin By now, you have probably heard that some PHP features, while convenient, can also cause PHP security problems.  This article discusses one of those, called register_globals.  It is a thing you do not want.  …
Author Note: Since this E-E article was originally written, years ago, formal testing has come into common use in the world of PHP.  PHPUnit (http://en.wikipedia.org/wiki/PHPUnit) and similar technologies have enjoyed wide adoption, making it possib…
The viewer will learn how to look for a specific file type in a local or remote server directory using PHP.
The viewer will learn how to create a basic form using some HTML5 and PHP for later processing. Set up your basic HTML file. Open your form tag and set the method and action attributes.: (CODE) Set up your first few inputs one for the name and …

739 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