This may help you in the right direction
<?php
session_start();
error_reporting(E_ALL);
if (!isset($_POST['subject']) && !isset($_POST['hobbies'])) {
// If neither submit has been pressed print this
print $subject = <<<_SUBJECT_
<form action="" method="post">
Science<input type="radio" name="science">
<br>
Computers<input type="radio" name="computers">
<br>
<input type="submit" name="subject" value="Submit">
</form>
_SUBJECT_;
} elseif (isset($_POST['subject']) && !isset($_POST['hobbies'])) {
// Add POST values to SESSION
if (isset($_POST['science'])) {$_SESSION['science'] = true;}
if (isset($_POST['computers'])) {$_SESSION['computers'] = true;}
$_SESSION['subject'] = true;
// If the first page has been submitted, but not the second Print this
print $hobbies = <<<_HOBBIES_
<form action="" method="post">
Singing<input type="radio" name="singing">
<br>
Music<input type="radio" name="music">
<br>
<input type="submit" name="hobbies" value="Submit">
</form>
_HOBBIES_;
} elseif (isset($_SESSION['subject']) && isset($_POST['hobbies'])) {
//If both submits have been pressed do the sql insert
$array = array(); //initialse the array variable
if (isset($_POST['singing'])) {$_SESSION['singing'] = true;}
if (isset($_POST['music'])) {$_SESSION['music'] = true;}
//go through the returned values and build query array
$message = 'You chose the following:<br> ';
if ($_SESSION['science'] == true) {
$message .='Science<br>';
$array['science'] = 1;
} else { $array['science'] = 0;}
if ($_SESSION['computers'] == true){
$message .='Computers<br>';
$array['computers'] = 1;
} else{ $array['computers'] = 0;}
if ($_SESSION['singing'] == true) {
$message.='Singing<br>';
$array[ 'singing'] = 1;
} else {$array[ 'singing'] = 0;}
if ($_SESSION['music'] == true) {
$message .='Music<br>';
$array['music'] = 1;
} else {$array['music'] = 0;
}
print $message; // Print message saying what has been selected
//loop through $array and build INSERT query
$sql = 'INSERT INTO table_name (';
foreach ($array as $key => $value){
$sql .= '\''.$key.'\', ';
}
$sql .= ') VALUES(';
foreach ($array as $key => $value){
$sql .= $value.', ';
}
$sql .=')';
//print $sql; //uncomment for debugging
// do your $sql insert here
session_destroy();
}
I have put it all on one page, no real need for three pages. Bear in mind that this is just a basic example, it does not for instance have any checking to prevent sql injection, and it of course uses a database table where all the possible values are either set to true or false.