First off I think you should use a radio button instead of a check box so the user can only select one choice.
After that... each script you have a check box linked to should have a name so it can be identified by the main script. Then the main script should have some php at the beginning of it to check to see if anything was submitted. If something was submitted, she script should identify what was submitted and load the appropriate page. If nothing was submitted, the main script should load as normal.
For instance, maybe something like this...
Code:
<?php
// Check to see if page was submitted
if(isset($_POST['submit'])){
// The main script was submitted, check to see if something was selected
if($_POST['arrays']){
// Arrays was selected, load array page
header("Location: ./arrays.php");
}
elseif($_POST['loops']){
// Loops was selected, load loops page
header("Location: ./loops.php");
}
// Nothing was selected but page was still submitted, display error message
else{
$error_message = "<div style=\"color:red;\">ERROR: Please select a page before clicking submit.</div>";
?>
<html><head>
<title>The Main Page</title>
</head><body>
Welcome to the main page! Select a page then click submit.
<?php echo $error_message ?>
</p>
<form action="./main.php" method="POST">
Arrays<input type="radio" name="arrays"><br>
Loops<input type="radio" name="loops"><br>
<input type="submit" value="Submit" name="submit">
</body></html>
<?php
}
}
else{
// The main page was not submitted, display main page as normal
?>
<html><head>
<title>The Main Page</title>
</head><body>
Welcome to the main page! Select a page then click submit.
</p>
<form action="./main.php" method="POST">
Arrays<input type="radio" name="arrays"><br>
Loops<input type="radio" name="loops"><br>
<input type="submit" value="Submit" name="submit">
</body></html>
<?php
}
?>
Now because I just went ahead just did all your homework for you lets go over it so you learn why this does what it does... :)
PHP works great with forms so your task isn't a difficult one. The first few lines just check to see if the page was submitted. If the form was submitted at all it would be submitted using post so PHP looks in the post array to see if something named "submit" was passed. If it was passed, PHP again looks in the post array for the name of the page you selected. If it find the page you selected PHP redirects to the page you selected. If PHP can't find your selection, this means you clicked "submit" without making a selection so the script loads the form with an error message.
Back to the beginning... if PHP didn't find submit in the post array, then the main page was never submitted (ie. This is the first time it has been loaded) and the page should display the form as normal.
If you look at the form, the inputs have names (ie. Name="arrays"). These names are what is passed to the post array. If these names differ from what PHP is looking for in the post array, or if these names don't exist at all, the script will fail. When adding more choices or changing your existing ones, take care to see that the name of the input is the same as what PHP is looking for in the array.