Having an issue with $_SESSION

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
Pinder
Forum Newbie
Posts: 1
Joined: Tue Nov 24, 2009 7:30 am

Having an issue with $_SESSION

Post by Pinder »

The Purpose of this form is to have 3 separate functions, one is to have a form that can edit lesson plans, two is to have a print preview section (preview), three so be able to submit the form by email. The issue I am having is the variables do not carry back over to the editing form from preview. Am I using sessions properly to save this information between forms? Any help would be appreciated. Thanks

Code: Select all

<?php
session_start();
$_SESSION['$session'] = $_POST['session'];
$_SESSION['$module'] = $_POST['module'];
$_SESSION['$subject'] = $_POST['subject'];
$_SESSION['$jobTask'] = $_POST['jobTask'];
$_SESSION['$trainingObjective'] = $_POST['trainingObjective'];
$_SESSION['$subobjective1'] = $_POST['subobjective1'];
$_SESSION['$subobjective2'] = $_POST['subobjective2'];
$_SESSION['$subobjective3'] = $_POST['subobjective3'];
$_SESSION['$subobjective4'] = $_POST['subobjective4'];
$_SESSION['$subobjective5'] = $_POST['subobjective5'];
$_SESSION['$instructionTechniques'] = $_POST['instructionTechniques'];
$_SESSION['$trainingAids'] = $_POST['trainingAids'];
$_SESSION['$trainingTime'] = $_POST['trainingTime'];
$_SESSION['$references'] = $_POST['references'];
 
?>
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Strict//EN" 
"http://www.w3.org/TR/xhtml1/DTD/xhtml1-strict.dtd">
<html xmlns="http://www.w3.org/1999/xhtml">
<head>
<title>Lesson Plan</title>
<LINK REL=StyleSheet HREF="../style.css" TYPE="text/css" MEDIA=screen>
<meta http-equiv="Content-Type" content="text/html; charset=iso-8859-1" />
</head>
<body>
<?php 
  $emailTo = 'pinder@address.com';
    if ($session == 'S1A'){$select01 = 'selected';}
    elseif($session == 'S1B'){$select02 = 'selected';}
    elseif($session == 'S2A'){$select03 = 'selected';}
    elseif($session == 'S2B'){$select04 = 'selected';}
    elseif($session == 'S3A'){$select05 = 'selected';}
    elseif($session == 'S3B'){$select06 = 'selected';}
    elseif($session == 'S4A'){$select07 = 'selected';}
    elseif($session == 'S4B'){$select08 = 'selected';}
    elseif($session == 'FSA'){$select09 = 'selected';}
    elseif($session == 'FSB'){$select10 = 'selected';}
    elseif($session == 'FSC'){$select11 = 'selected';}
    if($trainingTime == '30 Minutes'){$selectT01 = 'selected';}
    elseif($trainingTime == '1 Hour'){$selectT02 = 'selected';}
    elseif($trainingTime == '1.5 Hours'){$selectT03 = 'selected';}
    elseif($trainingTime == '2 Hours'){$selectT04 = 'selected';}
    elseif($trainingTime == '2.5 Hours'){$selectT05 = 'selected';}
    elseif($trainingTime == '3 Hours'){$selectT06 = 'selected';}
    elseif($trainingTime == '3.5 Hours'){$selectT07 = 'selected';}
    elseif($trainingTime == '4 Hours'){$selectT08 = 'selected';}
    elseif($trainingTime == '4.5 Hours'){$selectT09 = 'selected';}
    elseif($trainingTime == '5 Hours'){$selectT10 = 'selected';}
    elseif($trainingTime == '5.5 Hours'){$selectT11 = 'selected';}
    elseif($trainingTime == '6 Hours'){$selectT12 = 'selected';}
    elseif($trainingTime == '6.5 Hours'){$selectT13 = 'selected';}
    elseif($trainingTime == '7 Hours'){$selectT14 = 'selected';}
    elseif($trainingTime == '7.5 Hours'){$selectT15 = 'selected';}
    elseif($trainingTime == '8 Hours'){$selectT16 = 'selected';}
?>
<fieldset>
<legend>Lesson Plan</legend>
<form name="LessonPlanForm" method="post" action="<?php echo htmlentities($_SERVER['PHP_SELF']);?>">
<?php
if(isset($_POST['Submit'])){
Print_r ($_SESSION);
$message = "<br />Session:<br />$session<br />
Module:<br />$module<br />
Subject:<br />$subject<br />
Job Task:<br />$jobTask<br />
Training Objective:<br/> $trainingObjective<br />
Sub-Objective 1:<br /> $subobjective1<br />
Sub-Objective 2:<br /> $subobjective2<br />
Sub-Objective 3:<br /> $subobjective3<br />
Sub-Objective 4:<br /> $subobjective4<br />
Sub-Objective 5:<br /> $subobjective5<br />
Instructional Techniques:<br /> $instructionalTechniques<br /> 
Training Aids:<br /> $trainingAids<br /> 
Training Time:<br /> $trainingTime<br /> 
References:<br /> $references<br />";
mail($emailTo,$subject,$message);
 
echo "Form submit complete<br />";
echo "<input type='submit' value='Return' name='Return' /><br />";
}
if (isset($_POST['Preview'])&& !isset($_POST['Submit'])){
Print_r ($_SESSION);
?>
Session:<br /><?php echo $_SESSION['$session'];?></br />
Module:<br /><?php echo $_SESSION['$module'];?><br />
Subject:<br /><?php echo $_SESSION['$subject'];?><br />
Job Task:<br /><?php echo $_SESSION['$jobTask'];?><br />
Training Objective:<br /><?php echo $_SESSION['$trainingObjective'];?><br />
Sub-Objective 1:<br /><?php echo $_SESSION['$subobjective1'];?><br />
Sub-Objective 2:<br /><?php echo $_SESSION['$subobjective2'];?><br />
Sub-Objective 3:<br /><?php echo $_SESSION['$subobjective3'];?><br />
Sub-Objective 4:<br /><?php echo $_SESSION['$subobjective4'];?><br />
Sub-Objective 5:<br /><?php echo $_SESSION['$subobjective5'];?><br />
Instructional Techniques:<br /><?php echo $_SESSION['$instructionalTechniques'];?><br />
Training Aids:<br /><?php echo $_SESSION['$trainingAids'];?><br />
Training Time:<br /><?php echo $_SESSION['$trainingTime'];?><br />
References:<br /><?php echo $_SESSION['$references'];?><br />
<input type='submit' value='Return' name='Return' />
<?php }
if (isset($_POST['Reset']))
{
session_unset(); 
}
if ((!isset($_POST['Submit'])|| isset($_POST['Return'])) && !isset($_POST['Preview']))
{
Print_r ($_SESSION);
?>
<div id="mainForm">
<br />
Session:<br />
<select name="session">
   <option value="S1A" <?php echo $select01;?>>Sector 1 Session A</option>
   <option value="S1B" <?php echo $select02;?>>Sector 1 Session B</option>
   <option value="S2A" <?php echo $select03;?>>Sector 2 Session A</option>
   <option value="S2B" <?php echo $select04;?>>Sector 2 Session B</option>
   <option value="S3A" <?php echo $select05;?>>Sector 3 Session A</option>
   <option value="S3B" <?php echo $select06;?>>Sector 3 Session B</option>
   <option value="S4A" <?php echo $select07;?>>Sector 4 Session A</option>
   <option value="S4B" <?php echo $select08;?>>Sector 4 Session B</option>
   <option value="FSA" <?php echo $select09;?>>Fundamental Skills Session A</option>
   <option value="FSB" <?php echo $select10;?>>Fundamental Skills Session B</option>
   <option value="FSC" <?php echo $select11;?>>Fundamental Skills Session C</option>
</select><br />
 
Module:<br />
<textarea name="module" rows="2" cols="60"><?php Print ($_SESSION['$module']);?></textarea><br />
 
Subject:<br />
<textarea name="subject" rows="1" cols="90"><?php echo $_SESSION['$subject'];?></textarea><br />
 
Job Task:<br />
<textarea name="jobTask" rows="1" cols="90"><?php echo $_SESSION['$jobTask'];?></textarea><br />
 
Training Objective:<br />
<textarea name="trainingObjective" rows="3" cols="90"><?php echo $_SESSION['trainingObjective'];?></textarea><br />
 
Sub-Objectives or Steps:<br />
1.<textarea name="subobjective1" rows="3" cols="50"><?php echo $_SESSION['$subobjective1'];?></textarea><br />
2.<textarea name="subobjective2" rows="3" cols="50"><?php echo $_SESSION['$subobjective2'];?></textarea><br />
3.<textarea name="subobjective3" rows="3" cols="50"><?php echo $_SESSION['$subobjective3'];?></textarea><br />
4.<textarea name="subobjective4" rows="3" cols="50"><?php echo $_SESSION['subobjective4'];?></textarea><br />
5.<textarea name="subobjective5" rows="3" cols="50"><?php echo $_SESSION['subobjective5'];?></textarea><br />
 
Instructional Techniques:<br />
<textarea name="instructionalTechniques" rows="5" cols="90"><?php echo $_SESSION['instructionalTechniques'];?></textarea><br />
 
Training Aids Required:<br />
<textarea name="trainingAids" rows="3" cols="90"><?php echo $_SESSION['trainingAids'];?></textarea><br />
Training Time Required:<br />
<select name="trainingTime">
   <option value="30 Minutes" <?php echo $selectT01;?>>30 Minutes</option>
   <option value="1 Hour" <?php echo $selectT02;?>>1 Hour</option>
   <option value="1.5 Hours" <?php echo $selectT03;?>>1.5 Hours</option>
   <option value="2 Hours" <?php echo $selectT04;?>>2 Hours</option>
   <option value="2.5 Hours" <?php echo $selectT05;?>>2.5 Hours</option>
   <option value="3 Hours" <?php echo $selectT06;?>>3 Hours</option>
   <option value="3.5 Hours" <?php echo $selectT07;?>>3.5 Hours</option>
   <option value="4 Hours" <?php echo $selectT08;?>>4 Hours</option>
   <option value="4.5 Hours" <?php echo $selectT09;?>>4.5 Hours</option>
   <option value="5 Hours" <?php echo $selectT10;?>>5 Hours</option>
   <option value="5.5 Hours" <?php echo $selectT11;?>>5.5 Hour</option>
   <option value="6 Hours" <?php echo $selectT12;?>>6 Hours</option>
   <option value="6.5 Hours" <?php echo $selectT13;?>>6.5 Hours</option>
   <option value="7 Hours" <?php echo $selectT14;?>>7 Hours</option>
   <option value="7.5 Hours" <?php echo $selectT15;?>>7.5 Hours</option>
   <option value="8 Hours" <?php echo $selectT16;?>>8 Hours</option>
</select><br />
References:<br />
<textarea name="references" rows="4" cols="90"><?php echo $_SESSION['references'];?></textarea><br />
<input name="Submit" type="submit" value="Submit" />
<input name="Reset" type="submit" value="Reset" />
<input name="Preview" type="submit" value="Preview" />
</div>
<?php
}
?>
</form>
</fieldset>
</body>
</html>
User avatar
superdezign
DevNet Master
Posts: 4135
Joined: Sat Jan 20, 2007 11:06 pm

Re: Having an issue with $_SESSION

Post by superdezign »

Can't tell.. it's a bit sloppy. All I can see is that you don't seem to validate your form information, some variables are undefined without register_globals on ($session, $trainingTime), and you make use of variables that can be undefined depending on the logic ($select01, $selectT01, ...).

Also, you don't need the preceding dollar sign in strings. You are using them inconsistently, which could be causing problems. Just don't use them in your associative key names.

i.e. This:

Code: Select all

$_SESSION['$session']
Should be this:

Code: Select all

$_SESSION['session']
Post Reply