Ok here's teh whole code in the hope that someone can possibly see whats going wrong here. About to give up and use javascript but that will probably just bring up more problems!
Any help would be very very much appreciated!!!
Here's the code for the first page:
(I've removed some database stuff but I know half of this page is working as the redirect works fine??)
<?php require_once('Connections/database.php'); ?>
<?php
$your_email ='my email address';
session_start();
$errors = '';
$name = '';
$visitor_email = '';
$phone = '';
$city = '';
$interest = '';
$hear = '';
$newsletter = '';
$score = 0;
if(isset($_POST['submit']))
{
$name = $_POST['name'];
$visitor_email = $_POST['email'];
$phone = $_POST['phone'];
$city = $_POST['city'];
$interest = $_POST['interest'];
$hear = $_POST['hear'];
$newsletter = $_POST['newsletter'];
for($i=0;$i<11;$i++){
$answer = $_POST['radioq'.$i];
$score += $answer;
}
///------------Do Validations-------------
if(empty($name)||empty($visitor_email)||empty($phone)||empty($city))
{
$errors .= "\n Name, Email, Phone and City are required fields. ";
}
if(IsInjected($visitor_email))
{
$errors .= "\n Bad email value!";
}
if(empty($_SESSION['6_letters_code'] ) ||
strcasecmp($_SESSION['6_letters_code'], $_POST['6_letters_code']) != 0)
{
//Note: the captcha code is compared case insensitively.
//if you want case sensitive match, update the check above to
// strcmp()
$errors .= "\n The captcha code does not match!";
}
if(empty($errors))
{
//send the email
$to = $your_email;
$subject="form submission";
$from = $your_email;
$ip = isset($_SERVER['REMOTE_ADDR']) ? $_SERVER['REMOTE_ADDR'] : '';
$body = "A user called $name submitted the form:\n".
"Name: $name\n".
"Email: $visitor_email \n".
"Contact number: $phone\n".
"City: $city\n".
"$score \n".
"\n";
$headers = "From: $from \r\n";
$headers .= "Reply-To: $visitor_email \r\n";
mail($to, $subject, $body, $headers);
if ($score > 15) {
header('location: next-page.php?id=4');
} else if ($score > 11) {
header('location: next-page.php?id=3');
} else if ($score > 5) {
header('location: next-page.php?id=2');
} else {
header('location: next-page.php?id=1');
}
}
}
// Function to validate against any email injection attempts
function IsInjected($str)
{
$injections = array('(\n+)',
'(\r+)',
'(\t+)',
'(%0A+)',
'(%0D+)',
'(%08+)',
'(%09+)'
);
$inject = join('|', $injections);
$inject = "/$inject/i";
if(preg_match($inject,$str))
{
return true;
}
else
{
return false;
}
}
?>
And the code on the second page which should show the result:
<h1>Here are your results</h1>
<span style="font-size:3em;"><?php echo $_POST['score']; ?></span>
I think the problem is that the first page has the
if(isset($_POST['submit'])){
line which is causing the values not to be apssed to the next page? Does anyone know how I can keep the value $score available into the next page to display the score? I'm sooo stuck!! My 3rd day on this and I've read countless articles and tried different options and I'm still stuck. Please help!!