I have been stuck on this problem for 2 days now and still no joy.
I cannot see how the session var $username is being destroyed (if it is)- when i click submit the results of the query do not show nor can they be recovered in latter sessions.
here is the form:
<?php
include("include/session.php");
$username = $_SESSION['username'];
include("connect.php");
// query
$sql = "SELECT * FROM qualityuser WHERE username = '".$username."'";
$result = mysql_query($sql);
// if we have from rows then prepopulate the form
if(mysql_num_rows($result) > 0) {
$row = mysql_fetch_array($result);
} else {
$row = array('time'=>'','demand'=>'','external_support'=>'','training'=>'','complexity'=>'','depth'=>'','partuse'=>''
,'cost'=>'' ,'orgwhole'=>'','external_validated'=>'');
}
?>
///else display the form in HTML format
now the formhandler which also calculates scores like a Decision Support System- cannot show you all this as the code is over 500 lines but it isn;t relevant to the problem)
<?php
include("include/session.php");
include("connect.php");
//array to hold form errors
$form_error = array();
//validate your form data
if(!isset($_POST['time'])){
$form_error[] = "time not selected";
}
if(!isset($_POST['demand'])){
$form_error[] = "demand not selected";
}
if(count($form_error) > 0){
//hold the error in session so you can display the error in your form page.
$_SESSION['form_error'] = $form_error;
//redirect to the form
header("Location: http://www.mindseyemidlands.co.uk/notts_quality/info_resource/selfassess_part2a_v1.php");
} else {
$username = $_SESSION['username'];
//remove the form_error session
unset($_SESSION['form_error']);
$answer = array();
$answer[1] = $_POST['time'];
$answer[2] = $_POST['demand'];
$answer[3] = $_POST['external_support'];
$answer[4] = $_POST['training'];
$answer[5] = $_POST['depth'];
$answer[6] = $_POST['partuse'];
$answer[7] = $_POST['cost'];
$answer[8] = $_POST['orgwhole'];
$answer[9] = $_POST['external_validated'];
$sql = "UPDATE qualityuser SET time = '$answer[1]',
demand = '$answer[2]',
external_support = '$answer[3]',
training = '$answer[4]',
depth = '$answer[5]',
partuse = '$answer[6]',
cost = '$answer[7]',
orgwhole = '$answer[8]',
external_validated = '$answer[9]'
WHERE username = '$username'";
$result = mysql_query($sql) or exit(mysql_error());
function pqasso($answer)
{
$pqasso_score = 0;
//time needed
if ($answer[1] == "Flexible") {$pqasso_score = $pqasso_score + 1000;}
if ($answer[1] == "0-12 months") {$pqasso_score = $pqasso_score - 0;}
if ($answer[1] == "12 + months") {$pqasso_score = $pqasso_score - 0;}
//////////////////////// and so on
/ Store the result of the function in a variable
$pqasso_result = pqasso($answer);
$iip_result = iip($answer);
$iso_result = iso($answer);
$excel_result = excel($answer);
$social_result = social($answer);
$qmark_result = qmark($answer);
$chmark_result = chmark($answer);
$qfirst_result = qfirst($answer);
$balanced_result = balanced($answer);
$bigpic_result = bigpic($answer);
//get last insert id so we can update qualityuser based on the last inserted id
if (isset($_POST['submit'])) {
include "connect.php";
$scorearray[1] = $pqasso_result;
$scorearray[2] = $iip_result;
$scorearray[3] = $iso_result;
$scorearray[4] = $excel_result;
$scorearray[5] = $social_result;
$scorearray[6] = $qmark_result;
$scorearray[7] = $chmark_result;
$scorearray[8] = $qfirst_result;
$scorearray[9] = $balanced_result;
$scorearray[10] = $bigpic_result;
$qualitysystem[1] = "PQASSO";
$qualitysystem[2] = "Investors in People";
$qualitysystem[3] = "ISO Standards";
$qualitysystem[4] = "Excel";
$qualitysystem[5] = "Social Audit";
$qualitysystem[6] = "Quality Mark";
$qualitysystem[7] = "Charter Mark";
$qualitysystem[8] = "Quality First";
$qualitysystem[9] = "Balanced Scorecard";
$qualitysystem[10] = "Big Picture";
$searchurl[1] = "http://www.mindseyemidlands.co.uk/notts_quality/info_resource/qualitysystem_complete_details.php?quality_name=PQASSO";
$searchurl[2] = "http://www.mindseyemidlands.co.uk/notts_quality/info_resource/qualitysystem_complete_details.php?quality_name=IIP+(Investors+in+People)";
$searchurl[3] = "http://www.mindseyemidlands.co.uk/notts_quality/info_resource/qualitysystem_complete_details.php?quality_name=ISO+Standards";
$searchurl[4] = "http://www.mindseyemidlands.co.uk/notts_quality/info_resource/qualitysystem_complete_details.php?quality_name=EFQM+Excellence+Model+(European+Foundation+for+Quality+Management)";
$searchurl[5] = "http://www.mindseyemidlands.co.uk/notts_quality/info_resource/qualitysystem_complete_details.php?quality_name=Social+Accounting+and+Audit";
$searchurl[6] = "http://www.mindseyemidlands.co.uk/notts_quality/info_resource/qualitysystem_complete_details.php?quality_name=CLS+Quality+Mark+(Community+Legal+Services)";
$searchurl[7] = "http://www.mindseyemidlands.co.uk/notts_quality/info_resource/qualitysystem_complete_details.php?quality_name=Charter+Mark";
$searchurl[8] = "http://www.mindseyemidlands.co.uk/notts_quality/info_resource/qualitysystem_complete_details.php?quality_name=Quality+First";
$searchurl[9] = "http://www.mindseyemidlands.co.uk/notts_quality/info_resource/qualitysystem_complete_details.php?quality_name=Balanced+Scorecard";
$searchurl[10] = "Big Picture";
$values = array();
foreach($scorearray as $key => $score)
{
// each element will be a parenthesized list of values:
$values[] = sprintf("('%s','%s',%d,'%s')", $username, $qualitysystem[$key], $score, $searchurl[$key]);
}
// merge values into sequence of comma-separated value lists:
$valueList = implode(',', $values);
// create the SQL:
$sql = "INSERT INTO `qualityuserscores` (`username`, `qualitysystem`, `score`, `search_url`) VALUES $valueList";
$result = mysql_query($sql) or exit(mysql_error());
}
}
header("Location: http://www.mindseyemidlands.co.uk/notts_quality/info_resource/selfassess_part2b_v1.php?username=$username");
?>
and finally the query display page
include "include/session.php";
$username = $_SESSION['username'];
<?php
if (isset($_GET['username'])) {
include ("connect.php");
$course = mysql_real_escape_string($_GET['username']);
$sql = "SELECT * FROM qualityuserscores WHERE username = '$username' AND timeentered = NOW() ORDER BY score DESC";
$result = mysql_query($sql) or die(mysql_error());
if (mysql_num_rows($result) > 0) {
while ($row = mysql_fetch_assoc($result)) {
echo '
<TABLE BORDER=1 CELLPADDING=2>
<TR> <TH COLSPAN=2 BGCOLOR="#99CCFF"></TH> </TR>
<TR> <TD WIDTH=400><a href="' . $row['search_url'] . '">' . $row['qualitysystem'] . '</a></TD> <TD WIDTH=250>' . $row['score'] . '</TD> </TR>
</TR>
</TABLE>';
}
}
}
?>
i get no results when there is supposed to be a list of scores that can be recovered in another session. can anyone see what on earth im doing worn. Ive tried debugging but cannot see where my session is falling down
see for yourself
http://www.mindseyemidlands.co.uk/notts_quality/info_resource/selfassess_part2a_v1.php