gugie1 February 2016

Parse error: syntax error, unexpected 'else' (T_ELSE) in C:\xampp3\htdocs\wb_html\login.php on line 8

I' am tryin to make a registration and login system for my website and I am getting the parse error:syntax error unexpected 'else'(T_ELSE) in the login file when I click on login what could be the problem? Below is the file with the code:

    <?php
//include config
require_once('includes/config.php');

//check if already logged in move to home page
if($user->is_logged_in()){ 
    header('Location: index.php'); 
}
}
else
{

echo "<a href=register.php>Register</a>  <a href=login.php>Login</a>";
}   

//process login form if submitted
if(isset($_POST['submit'])){

    $username = $_POST['username'];
    $password = $_POST['password'];

    if($user->login($username,$password)){
        $_SESSION['username'] = $username;
        header('Location: memberpage.php');
        exit;

    } else {
        $error[] = 'Wrong username or password or your account has not been activated.';
    }

}//end if submit

//define page title
$title = 'Login';

Answers


AnkiiG February 2016

Two curly brackets are closed } after header('Location: index.php');. Make it one and try.


Gouda Elalfy February 2016

remove } after else :

if($user->is_logged_in()){ 
    header('Location: index.php'); 
} else {
    echo "<a href=register.php>Register</a>  <a href=login.php>Login</a>";
}


Pupil February 2016

You have one extra curly brace.

Change

//check if already logged in move to home page
if($user->is_logged_in()){ header('Location: index.php'); 

}
  }

To

//check if already logged in move to home page
if($user->is_logged_in()){ header('Location: index.php'); 

}


The avon guy February 2016

You have a double closed bracket before your first else statement; take one out:

if($user->is_logged_in()){ header('Location: index.php'); 

 }
   //} <- this is the extra one that shouldnt be there
  else
{


rdn87 February 2016

this is correct code, u Two curly brackets are closed }

//check if already logged in move to home page
if($user->is_logged_in()){ header('Location: index.php'); 

  }
  else
  {

echo "<a href=register.php>Register</a>  <a href=login.php>Login</a>";
}**strong text**   

//process login form if submitted
if(isset($_POST['submit'])){

    $username = $_POST['username'];
    $password = $_POST['password'];

    if($user->login($username,$password)){
        $_SESSION['username'] = $username;
        header('Location: memberpage.php');
        exit;

    } else {
        $error[] = 'Wrong username or password or your account has not been activated.';
    }

}//end if submit

//define page title
$title = 'Login';


ArrowHead February 2016

Format your code well, you had double curly brackets in your code.

//include config
require_once('includes/config.php');

//check if already logged in move to home page
if($user->is_logged_in()){

    header('Location: index.php');

} else {

      echo "<a href=register.php>Register</a>  <a href=login.php>Login</a>";
  }   

//process login form if submitted
if(isset($_POST['submit'])){

    $username = $_POST['username'];
    $password = $_POST['password'];

    if($user->login($username,$password)){
        $_SESSION['username'] = $username;
        header('Location: memberpage.php');
        exit;

    } else {
        $error[] = 'Wrong username or password or your account has not been activated.';
    }

}//end if submit

//define page title
$title = 'Login';


Jalpa February 2016

You have added extra } in if loop. Please replace below code.

//include config
require_once('includes/config.php');

//check if already logged in move to home page
if($user->is_logged_in()){ 
   header('Location: index.php'); 
}
else
{
   echo "<a href=register.php>Register</a>  <a href=login.php>Login</a>";
} 


devpro February 2016

You have an extra closing bracket here:

if($user->is_logged_in()){ header('Location: index.php'); 

}
  }
....

This should be like:

if($user->is_logged_in())
{ 
    header('Location: index.php'); 
}
else
{
    echo "<a href=register.php>Register</a>  <a href=login.php>Login</a>";
} 

Side Note:

I suggest you to always use proper formatting this will help you to find out these kind of issues.

Post Status

Asked in February 2016
Viewed 2,440 times
Voted 8
Answered 8 times

Search




Leave an answer