Can't seem to get my session variable append up a value

PHP programming forum. Ask questions or help people concerning PHP code. Don't understand a function? Need help implementing a class? Don't understand a class? Here is where to ask. Remember to do your homework!

Moderator: General Moderators

Post Reply
User avatar
edawson003
Forum Contributor
Posts: 133
Joined: Thu Aug 20, 2009 6:34 am
Location: Los Angeles, CA - USA

Can't seem to get my session variable append up a value

Post by edawson003 »

I can't seem to get my session variable append up a value when an add button is pressed. The variable keeps reseting to 1. I want to be able to add 1, everytime a button is clicked.

Code: Select all

 
<?
$set = 0;
if(!isset($_SESSION['trueset'])){
echo "Session not set<br>";
}
else{
echo $_SESSION['trueset'];
}
 
if(!isset($_SESSION['trueset'])){
$_SESSION['trueset'] = $_GET['trueset'];
setcookie("trueset", $_SESSION['trueset'], time()+60*60*24*100, "/"); [color=#FF0000]/* I thought maybe setting the session as a cookie might help the initial set value stick */[/color]
}
 
if(isset($_POST['addaset_x'])){ [color=#FF0000]/* addaset is a name of submit button within a form */[/color]        
                 $trueset = $_SESSION['trueset'] + 1;
                 header( "Location: http://www.url.com/membersarea/ButtonTe ... t=$trueset" );              
                 }
 
User avatar
papa
Forum Regular
Posts: 958
Joined: Wed Aug 27, 2008 3:36 am
Location: Sweden/Sthlm

Re: Can't seem to get my session variable append up a value

Post by papa »

You need session_start() in the beginning of the page.
User avatar
edawson003
Forum Contributor
Posts: 133
Joined: Thu Aug 20, 2009 6:34 am
Location: Los Angeles, CA - USA

Re: Can't seem to get my session variable append up a value

Post by edawson003 »

awwww. thx, the session_start() did it!!! You are a PHP guru!
User avatar
papa
Forum Regular
Posts: 958
Joined: Wed Aug 27, 2008 3:36 am
Location: Sweden/Sthlm

Re: Can't seem to get my session variable append up a value

Post by papa »

edawson003 wrote:awwww. thx, the session_start() did it!!! You are a PHP guru!
I know, ask the others... :)
Post Reply