So, I have this RPG game I've been working on using PHP for the hell of it. I've been trying to get some sessions to work for quite some time to save my variables over various pages, which, obviously, is what they're intended for. Here's the code related to my problem from my page:
Line 1: <?php session_start(); ?>
This part is just determining the results from the form the user fills out to "create their character"
if ($_GET["race"]=="Human"){
$_SESSION["race"] = "Human";
$_SESSION["raceadj"] = "Human";
$_SESSION['racestrengthbonus'] = 0;
$_SESSION['raceendurancebonus'] = 0;
$_SESSION['raceintellectbonus'] = 0;
$_SESSION['racewillpowerbonus'] = 0;
$_SESSION['raceluckbonus'] = 0;
and for the class
if ($_GET["career"]=="Knight"){
$_SESSION["career"] = "Knight";
$_SESSION['classstrengthbonus'] = 10;
$_SESSION['classendurancebonus'] = 10;
$_SESSION['classintellectbonus'] = 0;
$_SESSION['classwillpowerbonus'] = 0;
$_SESSION['classluckbonus'] = 0;
$_SESSION['RightHand'] = "Iron Sword";
$_SESSION['LeftHand'] = "Wooden Shield";
$_SESSION['Armor'] = "Iron Armor";
Now here's the code where all of that is being used.
<?PHP
echo "<div class=\"playerstats\" align=\"center\"><span class=\"playername\">".$_GET["name"]."</span><br><span class=\"redtext\">".$_SESSION["race"]." - ".$_SESSION['career']." - ".$_SESSION["health"]." HP - ".$_SESSION["gold"]." Gold</div>
<div style=\"float:left\"><span class=\"redtext\">Strength: </span>".$_SESSION["strength"]."<br>
<span class=\"redtext\">Endurance: </span>".$_SESSION["endurance"]."<br>
<span class=\"redtext\">Intellect: </span>".$_SESSION["intellect"]."<br>
<span class=\"redtext\">Willpower: </span>".$_SESSION["willpower"]."<br>
<span class=\"redtext\">Luck: </span>".$_SESSION["luck"]."<br></div>";
echo "<div class=\"equipment\"><span class=\"hover right\">".$_SESSION["RightHand"]."</span><span class=\"redtext\"> - Right Hand</span><br>
<span class=\"hover left\">".$_SESSION['LeftHand']."</span><span class=\"redtext\"> - Left Hand</span><br>
<span class=\"hover\">".$_SESSION['Armor']."</span><span class=\"redtext\"> - Armor</span><br></div>"; ?>
When I first load up this page, everything displays correctly. The name, race, etc all displays what the user put in their form, but if the user uses any of the actions on the page (which are simply forms that display the results on this same page) then it doesn't save the variables and goes right to the "else" results of both race and class, with no name saved. I'm not sure what I'm doing wrong. Any help?