session variables not working

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
ianmullineaux
Forum Newbie
Posts: 4
Joined: Thu Oct 23, 2008 7:28 am

session variables not working

Post by ianmullineaux »

Hi
I havent been using PHP long but have done a few simple things before. I have used session variables in the past and they worked but this time i am having problems. The php variables must be getting the data from the form as the conditions and simple error checking is working but nothing seems to be passed to the session variables..

I know the code is a bit long winded but i was keeping it simple so I could follow it and find out what was wrong - could someone point me in the right direction please..

the code is below
<?php session_start();

if(isset($_POST['Submit']))
{
$band = $_POST['band'];
$job_title = $_POST['job_title'];
$area = $_POST['name'];
$days_worked = $_POST['days_worked'];
$hours_worked = $_POST['hours_worked'];
$hours_mon = $_POST['hours_mon'];
$hours_tue = $_POST['hours_tue'];
$hours_wed = $_POST['hours_wed'];
$hours_thu = $_POST['hours_thu'];
$hours_fri = $_POST['hours_fri'];
$hours_sat = $_POST['hours_sat'];
$hours_sun = $_POST['hours_sun'];
$overtime = $_POST['overtime'];

$problems = "No";
$problems_band = "No";
$problems_job_title = "No";
$problems_area = "No";
$problems_days_worked = "No";
$problems_hours_worked = "No";
$problems_hours_mon = "No";
$problems_hours_tue = "No";
$problems_hours_wed = "No";
$problems_hours_thu = "No";
$problems_hours_fri = "No";
$problems_hours_sat = "No";
$problems_hours_sun = "No";
$problems_overtime = "No";


if ($band == 0 )
{
$problems = "Yes";
$problems_band = "Yes";
}
if ($job_title == 0 )
{
$problems = "Yes";
$problems_job_title = "Yes";
}
if ($area == 0 )
{
$problems = "Yes";
$problems_area = "Yes";
}
if ($days_worked == 0 )
{
$problems = "Yes";
$problems_days_worked = "Yes";
}
if ($days_worked > 7 )
{
$problems = "Yes";
$problems_days_worked = "Yes";
}

if ($hours_worked == 0 )
{
$problems = "Yes";
$problems_hours_worked = "Yes";
}

if ($hours_mon + $hours_tue + $hours_wed + $hours_thu + $hours_fri + $hours_sat + $hours_sun != $hours_worked )
{
$problems = "Yes";
$problems_daily_hours = "Yes";
}

if ($problems =="No")
{
$_SESSION['band'] = $band;
$_SESSION['job_title'] = $job_title;
$_SESSION['area']=$area;
$_SESSION['days_worked'] = $days_worked;
$_SESSION['hours_worked'] = $hours_worked;
$_SESSION['hours_mon'] = $hours_mon;
$_SESSION['hours_tue'] = $hours_tue;
$_SESSION['hours_wed'] = $hours_wed;
$_SESSION['hours_thu'] = $hours_thu;
$_SESSION['hours_fri'] = $hours_fri;
$_SESSION['hours_sat'] = $hours_sat;
$_SESSION['hours_sun'] = $hours_sun;
$_SESSION['overtime'] = $overtime;
header("Location: survey2.php");
}
}

?>

<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
<html xmlns="http://www.w3.org/1999/xhtml">
<head>
<meta http-equiv="Content-Type" content="text/html; charset=iso-8859-1" />
<title>NWAS eLearning Zone</title>
<link href="../css/site.css" rel="stylesheet" type="text/css" />
<meta name="robots" content="noindex, nofollow">
<script src="js/AjaxCode.js"></script>
</head>

<body>
<div id="header">
<div id="header-left"><img src="../images/pagelayout/crest.jpg" /></div>
<div id="header-right"><img src="../images/pagelayout/nwasNHS.jpg" width="450" height="100" /></div>
</div>
<div id="bluebar"></div>
<div id="contentwrapper">

<div id="inner-content-wide">

<form action="survey1.php" method="post" name="form1" id="form1" >
<h2>Part 1: Job Details</h2>
<table width="812" height="343" border="0" align="center" cellpadding="0" cellspacing="0" class="table_form">
<tr>
<td align="right">What Band are you?</td>
<td width="23"></td>
<td colspan="7"><select name="bandlist" id="bandlist" onChange="return bandlistOnChange()">
<option value="0" selected="selected">Please Select...</option>
<option value="6">Band 6</option>
<option value="7">Band 7</option>
</select></td>
</tr>
<tr>
<td align="right">What is your Job Title?</td>
<td>&nbsp;</td>
<td colspan="7"><label>
<select name="jobtitlelist" id="jobtitlelist">
</select>
</label></td>
</tr>
<tr>
<td align="right">What area within NWAS do you work?</td>
<td>&nbsp;</td>
<td colspan="7"><label>
<select name="area" id="area">
<option value="0" selected="selected">Please Select...</option>
<option value="Cumbria">Cumbria</option>
<option value="Cheshire and Mersey">Cheshire and Mersey</option>
<option value="Greater Manchester">Greater Manchester</option>
<option value="Lancashire">Lancashire</option>
</select>
</label></td>
</tr>
<tr>
<td align="right">How many days have you worked this week?</td>
<td>&nbsp;</td>
<td colspan="7"><input name="days_worked" type="text" id="days_worked" value="0" size="5" maxlength="5" /></td>
</tr>
<tr>
<td align="right">How many hours have you worked this week?</td>
<td>&nbsp;</td>
<td colspan="7"><label>
<input name="hours_worked" type="text" id="hours_worked" value="0" size="5" maxlength="5" />
</label></td>
</tr>
<tr>
<td rowspan="2" align="right">How many hours have you worked each day?<br />
<em><strong>(If not worked enter 0)</strong></em></td>
<td>&nbsp;</td>
<td width="49" align="center">Mon</td>
<td width="49" align="center">Tue</td>
<td width="49" align="center">Wed</td>
<td width="49" align="center">Thu</td>
<td width="49" align="center">Fri</td>
<td width="49" align="center">Sat</td>
<td width="49" align="center">Sun</td>
</tr>
<tr>
<td>&nbsp;</td>
<td width="49" align="center"><input name="hours_mon" type="text" id="hours_mon" value="0" size="5" maxlength="5" /></td>
<td width="49" align="center"><input name="hours_tue" type="text" id="hours_tue" value="0" size="5" maxlength="5" /></td>
<td width="49" align="center"><input name="hours_wed" type="text" id="hours_wed" value="0" size="5" maxlength="5" /></td>
<td width="49" align="center"><input name="hours_thu" type="text" id="hours_thu" value="0" size="5" maxlength="5" /></td>
<td width="49" align="center"><input name="hours_fri" type="text" id="hours_fri" value="0" size="5" maxlength="5" /></td>
<td width="49" align="center"><input name="hours_sat" type="text" id="hours_sat" value="0" size="5" maxlength="5" /></td>
<td width="49" align="center"><input name="hours_sun" type="text" id="hours_sun" value="0" size="5" maxlength="5" /></td>
</tr>
<tr>
<td align="right">How many additional hours have you worked this week(as overtime) to complete your managerial/administrative tasks? <em><strong><br />(If none please enter 0)</strong></em>.</td>
<td>&nbsp;</td>
<td colspan="7" valign="middle"><input name="overtime" type="text" id="overtime" value="0" size="5" maxlength="5" /></td>
</tr>
<tr>
<td height="50" colspan="9" align="center" valign="bottom"><label>
<input type="submit" name="Submit" id="Submit" value="Continue to Activities Section >>" />
</label><div style="display:none;">
<input type="text" name="myemail" value=""></div></td>
</tr>
</table>
<p>&nbsp; </p>
</form>
</div>

<div id="footer"></div>
</div>
</div>

</body>
</html>
User avatar
papa
Forum Regular
Posts: 958
Joined: Wed Aug 27, 2008 3:36 am
Location: Sweden/Sthlm

Re: session variables not working

Post by papa »

Do you have session_start() in your survery2.php document?
ianmullineaux
Forum Newbie
Posts: 4
Joined: Thu Oct 23, 2008 7:28 am

Re: session variables not working

Post by ianmullineaux »

yes - right at the top of the page - 1st item
User avatar
VladSun
DevNet Master
Posts: 4313
Joined: Wed Jun 27, 2007 9:44 am
Location: Sofia, Bulgaria

Re: session variables not working

Post by VladSun »

Try to add session_write_close(); before the header(...); line and exit() after the header() line
There are 10 types of people in this world, those who understand binary and those who don't
ianmullineaux
Forum Newbie
Posts: 4
Joined: Thu Oct 23, 2008 7:28 am

Re: session variables not working

Post by ianmullineaux »

still not working -
User avatar
VladSun
DevNet Master
Posts: 4313
Joined: Wed Jun 27, 2007 9:44 am
Location: Sofia, Bulgaria

Re: session variables not working

Post by VladSun »

Take a look at http://bugs.php.net/bug.php?id=14636 and users' comments.
There are 10 types of people in this world, those who understand binary and those who don't
Post Reply