-
Parse error: syntax error, unexpected T_ELSE
I have a script for a simple multi page form using sessions. I also have a simple script to add an inline error message on the same form. When I try to combine the two I am given a Parse error. It happens on:
else if ($stage == 2)
I think there is a lot here that I am messing up with, mostly, the placement of some functions. Any help is appreciated.
Here is the combined code:
<?php//Turn on sessions
session_start();//Find what stage to use
if (($_SERVER['REQUEST_METHOD'] == 'GET') || (!isset($_POST['stage'])))
{
$stage = 1;
}
else
{
$stage = (int) $_POST['stage'];
}// Save any submitted data
if ($stage > 1)
{
foreach ($_POST as $key => $value)
{
$_SESSION[$key] = $value;
}
}
if ($stage == 1)
{//just display the form if the request is GET
display_form(array());
}
else
{
//the request is a POST so validate the form
$errors = validate_form();
if (count($errors))
{
//if there were any errors, redisplay the form with the errors
display_form($errors);
}
else
{
//the form data was valid so print a congratulations message
print 'the form was submitted.';
}
}function display_form($errors)
{
//set up defaults
$defaults['first_name'] = isset($_POST['first_name']) ? htmlentities($_POST['first_name']) : '';?>