thankyou nogdog- how about in this instance of this more complicated script:
form.php
<?php
include("include/session.php");
$_SESSION['formdata1']='';
$username = $_SESSION['username'];
$totalscore = $_SESSION['totalscore'];
include("connect.php");
// query
$sql = "SELECT * FROM qualityuser WHERE username = '".$username."'";
$result = mysql_query($sql);
// if we have rows, fetch them & prepopulate the form
if(mysql_num_rows($result) > 0) {
formhandler.php
include("include/session.php");
$username = $_SESSION['username'];
$totalscore = $_SESSION['totalscore'];
if(isset($_POST['submit'])){
include("connect.php");
$message = NULL;
$score = 0;
$score_pol_proc = 0;
//validate your form data
if (empty($_POST['firstname'])) {
$message .= '<p>You forgot to enter your first name!</p>';
}
// Check for an second name.
if (empty($_POST['secondname'])) {
$message .= '<p>You forgot to enter your second name</p>';
}
if (empty($_POST['organisation'])) {
$message .= '<p>You forgot to enter your organisation</p>';
}
if(count($message) > 0){
//hold the error in session so you can display the error in your form page.
$_SESSION['message'] = $message;
//redirect to the form
header("Location: http://www.mindseyemidlands.co.uk/notts_quality/info_resource/selfassess_part1a_v1.php");
}
else {
$query = "SELECT * FROM qualityuser WHERE username = '".$username."'";
$result = mysql_query($query);
$num = mysql_num_rows ($result);
if ($num == 1) {
//etc
//and
if ($num == 0) {
$_SESSION['formdata1']=$_POST;
$username = $_SESSION['username'];
// build insert query from session formdata
$sql = "INSERT INTO qualityuser SET qualityuser_id = NULL ";
foreach ($_SESSION['formdata1'] as $col =>$val ){
if($col <> 'submit'){
$sql .=", $col = '$val' ";
}
}
mysql_query($sql, $connection) or die(mysql_error());
//remove the form_error session
unset($_SESSION['message']);
//set up an array for answers to 'organisation types'
$orgtype = array();
// add values, if they exist
if(isset($_POST['registeredcharity'])) { $orgtype[1] = $_POST['registeredcharity']; }
if(isset($_POST['incorporated'])) { $orgtype[2] = $_POST['incorporated']; }
if(isset($_POST['regionalassociation'])) { $orgtype[3] = $_POST['regionalassociation']; }
if(isset($_POST['regionalcharity'])) { $orgtype[4] = $_POST['regionalcharity']; }
if(isset($_POST['project'])) { $orgtype[5] = $_POST['project']; }
//score for organisation type
foreach($orgtype as $key=>$value)
{
if($value == "1")
{
$score = $score + 5;
}
else
{
$score = $score + 0;
}
}
//scores for nature of organisation
$orgnature = array();
if(isset($_POST['nature_selfhelp'])) { $orgnature[1] = $_POST['nature_selfhelp']; }
if(isset($_POST['nature_frontline'])) { $orgnature[2] = $_POST['nature_frontline']; }
if(isset($_POST['nature_intermediary'])) { $orgnature[3] = $_POST['nature_intermediary']; }
if(isset($_POST['nature_infrastructure'])) { $orgnature[4] = $_POST['nature_infrastructure']; }
if(isset($_POST['nature_partnership'])) { $orgnature[5] = $_POST['nature_partnership']; }
if($orgnature[1] == "1")
{
$score = $score + 5;
}
if($orgnature[2] == "1")
{
$score = $score + 5;
}
if($orgnature[3] == "1")
{
$score = $score + 10;
}
if($orgnature[4] == "1")
{
$score = $score + 10;
}
if($orgnature[5] == "1")
{
$score = $score + 15;
}
// scores for number of staff/volunteers
$numstaff = array();
if(isset($_POST['involved_commitee'])) { $numstaff[1] = $_POST['involved_commitee']; }
if(isset($_POST['involved_volunteers'])) { $numstaff[2] = $_POST['involved_volunteers']; }
if(isset($_POST['involved_paid'])) { $numstaff[3] = $_POST['involved_paid']; }
foreach($numstaff as $key=>$value)
{
if($value == "5 or less")
{
$score = $score + 2;
}
if($value == "6 to 10")
{
$score = $score + 4;
}
if($value == "11 to 25")
{
$score = $score + 6;
}
if($value == "26 to 50")
{
$score = $score + 8;
}
if($value == "Over 50")
{
$score = $score + 10;
}
}
// add another 10 points for 5 or more volunteers
if ($numstaff[2] = "6 to 10" || "11 to 25" || "26 to 50" || "50 and over")
$score = $score + 10;
//scoring for funding
$fundingscore = array();
// add values, if they exist
if(isset($_POST['funded_unrestrictedfunds'])) { $fundingscore[1] = $_POST['funded_unrestrictedfunds']; }
if(isset($_POST['funded_localcouncil'])) { $fundingscore[2] = $_POST['funded_localcouncil']; }
if(isset($_POST['funded_undercontract'])) { $fundingscore[3] = $_POST['funded_undercontract']; }
if(isset($_POST['funded_grants_fees'])) { $fundingscore[4] = $_POST['funded_grants_fees']; }
if(isset($_POST['funded_socialenterprise'])) { $fundingscore[5] = $_POST['funded_socialenterprise']; }
if($fundingscore[1] == "1")
{
$score = $score + 5;
}
if($fundingscore[2] == "1")
{
$score = $score + 10;
}
if($fundingscore[3] == "1")
{
$score = $score + 10;
}
if($fundingscore[4] == "1")
{
$score = $score + 0;
}
if($fundingscore[5] == "1")
{
$score = $score + 5;
}
//scoring for organisation activities
$orgactivity = array();
if(isset($_POST['activity_care'])) { $orgactivity[1] = $_POST['activity_care']; }
if(isset($_POST['activity_advice_individual'])) { $orgactivity[2] = $_POST['activity_advice_individual']; }
if(isset($_POST['activity_advice_organisations'])) { $orgactivity[3] = $_POST['activity_advice_organisations']; }
if(isset($_POST['activity_specialist'])) { $orgactivity[4] = $_POST['activity_specialist']; }
if(isset($_POST['activity_community'])) { $orgactivity[5] = $_POST['activity_community']; }
if(isset($_POST['activity_awareness'])) { $orgactivity[6] = $_POST['activity_awareness']; }
if(isset($_POST['activity_sport'])) { $orgactivity[7] = $_POST['activity_sport']; }
if(isset($_POST['activity_mutual_support'])) { $orgactivity[8] = $_POST['activity_mutual_support']; }
if ($orgactivity[1] || $orgactivity[2] || $orgactivity[3] =="1")
$score = $score + 20;
if ($orgactivity[4] || $orgactivity[5] || $orgactivity[6] =="1")
$score = $score + 10;
if ($orgactivity[7] || $orgactivity[8] =="1")
$score = $score + 5;
// scoring for policies and procedures- this is a separate variable score as the total will be taken off the
//total of $score sub total
$pol_proc = array();
if(isset($_POST['have_policies_procedures'])) { $pol_proc[1] = $_POST['have_policies_procedures']; }
if(isset($_POST['have_management_structure'])) { $pol_proc[2] = $_POST['have_management_structure']; }
if(isset($_POST['have_communication'])) { $pol_proc[3] = $_POST['have_communication']; }
if(isset($_POST['have_supervision'])) { $pol_proc[4] = $_POST['have_supervision']; }
if(isset($_POST['have_strategy'])) { $pol_proc[5] = $_POST['have_strategy']; }
if(isset($_POST['have_aims'])) { $pol_proc[6] = $_POST['have_aims']; }
if(isset($_POST['have_review'])) { $pol_proc[7] = $_POST['have_review']; }
if ($pol_proc[1] =="1")
$score_pol_proc = $score_pol_proc + 15;
if ($pol_proc[2] || $pol_proc[3] || $pol_proc[4] =="1")
$score_pol_proc = $score_pol_proc + 10;
if ($pol_proc[5] || $pol_proc[6] || $pol_proc[7] =="1")
$score_pol_proc = $score_pol_proc + 5;
}
// Create a grand total by taking $pol_proc_score away from $scorePrint the number of points:
$totalscore = $score - $score_pol_proc;
$_SESSION['totalscore'] = $totalscore;
//redirect to result display page
header("Location: http://www.mindseyemidlands.co.uk/notts_quality/info_resource/selfassess_part1b_v1.php");
//define variables
}
?>
results.php
<?php
include("include/session.php");
$username = $_SESSION['username'];
?>
echo 'You scored <strong>'. $totalscore . '</strong> points!';
echo '<br><br>';
if ($totalscore >= 26) echo 'Your responses indicate that you fall within the category of needing to adopt a full quality system. This could be either generic or specialist - or perhaps both. For that reason we recommend the following:
<table width="700" border="0">
//etc......