I have tried this on a scoring session system and it doesn't work out - the query doesn't insert data into the database:
form.php
<?php
include("include/session.php");
include("common_functions.php");
$totalscore = TRUE;
$_SESSION['formdata1']='';
$username = quote_smart($_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) {
$row = mysql_fetch_array($result);
} else {
$row = array('firstname'=>'','secondname'=>'','organisation'=>'','telephone'=>'','address1'=>'','address2'=>'','town'=>''
,'postcode'=>'' ,'registeredcharity'=>'','incorporated'=>'','regionalassociation'=>'','regionalcharity'=>'','project'=>''
,'nature_selfhelp'=>'','nature_frontline'=>'','nature_intermediary'=>'','nature_infrastructure'=>'','nature_partnership'=>''
,'involved_commitee'=>'','involved_volunteers'=>'','involved_paid'=>'','funded_unrestrictedfunds'=>'','funded_localcouncil'=>''
,'funded_undercontract'=>'','funded_grants_fees'=>'','funded_socialenterprise'=>'','activity_care'=>'','activity_advice_individual'=>''
,'activity_advice_organisations'=>'','activity_specialist'=>'','activity_community'=>'','activity_awareness'=>'','activity_sport'=>''
,'activity_mutual_support'=>'','have_policies_procedures'=>'','have_management_structure'=>'','have_communication'=>'','have_supervision'=>''
,'have_strategy'=>'','have_aims'=>'','have_review'=>'');
}
?>
processor.php
<?php
error_reporting(E_ALL);
include("include/session.php");
include("common_functions.php");
$username = quote_smart($_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 ($num == 0) {
$_SESSION['formdata1']=$_POST;
$username = quote_smart($_SESSION['username']);
// build insert query from session formdata
$sql = "INSERT INTO qualityuser SET qualityuser_id = NULL ";
foreach ($_SESSION['formdata1'] as $col =>$value ){
if($col <> 'submit'){
$sql .=", $col = '".quote_smart($value)."' ";
}
}
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
////etc/////
// 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/result.php");
//define variables
}
?>
result.php
<?php
include("include/session.php");
include("common_functions.php");
$username = quote_smart($_SESSION['username']);
$totalscore = $_SESSION['totalscore'];
?>
<?php
echo 'Thankyou <strong>'. $username . '</strong><br>';
echo 'You scored <strong>'. $totalscore . '</strong> points!';
echo '<br><br>';
if ($totalscore >= 26) echo 'xxxx';
////etc////;?>
common_functions.php
error_reporting(E_ALL ^ E_NOTICE);
// Quote variable to make safe
function quote_smart($value)
{
// Stripslashes
if (get_magic_quotes_gpc()) {
$value = stripslashes($value);
}
// Quote if not integer
if (!is_numeric($value)) {
$value = "'" . mysql_real_escape_string($value) . "'";
}
return $value;
}
i get no error messages but the record is not inserted so the score stays at 0