Hi guys,

My first post here after reading some very helpful responses over the last few months.
I'm having trouble passing radio button values to a results page and wondered if anyone would be able to spot anything wrong with the following code?

Any ideas are very much appreciated as this is the first time I've used PHP forms with radio buttons...

Here's the code section for the form page:

if(isset($_POST['submit']))
{   
    $name = $_POST['name'];
    $visitor_email = $_POST['email'];
    $phone = $_POST['phone'];
    $city = $_POST['city'];
    $interest = $_POST['interest'];
    $hear = $_POST['hear'];
    $radioq1 = $_POST['radioq1'];
    $radioq2 = $_POST['radioq2'];
    $radioq3 = $_POST['radioq3'];
    $radioq4 = $_POST['radioq4'];
    $radioq5 = $_POST['radioq5'];
    $radioq6 = $_POST['radioq6'];
    $radioq7 = $_POST['radioq7'];
    $radioq8 = $_POST['radioq8'];
    $radioq9 = $_POST['radioq9'];
    $radioq10 = $_POST['radioq10'];
    $score = 0;
}

These are the NAMES for the form entries which then get POSTed to another page that just processes:

<?php

$points = $_POST['$score + $radioq1 + $radioq2 + $radioq3 + $radioq4 + $radioq5 + $radioq6 + $radioq7 + $radioq8 + $radioq9 + $radioq10'];

if ($points > 15) {
        header('location: results-page.php?id=4');
} else if ($points > 11) {
        header('location: results-page.php?id=3');
} else if ($points > 5) {
        header('location: results-page.php?id=2');
} else {
        header('location: results-page.php?id=1');
    }
?>

The final page just shows the page and draws text and images from a database so simple stuff. The only thing is I can't get the values to add up! The result is always the same: results-page?id=1

Iknow it's something simple but my head hurts!!!

Hi koldhands,
Is there any field in your markup with name="submit". If not change the line containing 'isset' to

isset($_POST['name'])

or

isset($_POST['email'])

or with name of any other field or simply use:

if ($_SERVER['REQUEST_METHOD'] == 'POST')

.
Hope this helps...

Sorry after posting I realised there's a few things I should have included in the post: the form does have a submit button and the process page is only there to make it easier for me to check eveything works. I'll eventually paste the 2 pages together once I get it working.
Also, just to be a bit clearer, the specific problem is that I can't collect the score values.
Thanks Hari for the response though!

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; ?></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!!

you can check isset to check whether they have some value.. I think the result of addition you perform is always less than 5..

Be a part of the DaniWeb community

We're a friendly, industry-focused community of developers, IT pros, digital marketers, and technology enthusiasts meeting, networking, learning, and sharing knowledge.