Page 1 of 1

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

Posted: Wed Nov 25, 2009 10:06 am
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" );              
                 }
 

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

Posted: Wed Nov 25, 2009 10:09 am
by papa
You need session_start() in the beginning of the page.

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

Posted: Wed Nov 25, 2009 10:35 am
by edawson003
awwww. thx, the session_start() did it!!! You are a PHP guru!

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

Posted: Wed Nov 25, 2009 10:38 am
by papa
edawson003 wrote:awwww. thx, the session_start() did it!!! You are a PHP guru!
I know, ask the others... :)