Page 1 of 1

Unexpected T_ELSE Statement

Posted: Wed May 31, 2006 4:53 pm
by a94060
Hi, I have this script here and im not sure why i am getting this error:

My script is :

Code: Select all

<?PHP
session_start();
//simple check to see if the person is logged in
if($_SESSION['in'] != TRUE) {
echo 'You are not logged in,please log in at the admin area.';
}
?>
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
<html xmlns="http://www.w3.org/1999/xhtml">
<head>
<meta http-equiv="Content-Type" content="text/html; charset=iso-8859-1" />
<title>Admin Page</title>
<style type="text/css">
<!--
.style1 {font-size: 16px}
.style4 {font-size: 24px}
-->
</style>
</head>

<body>
<h1>
  <?PHP
else {
?>
</h1>
<div align="center" class="style1">
  <p class="style4"> Admin Login</p>
  <form id="form1" name="form1" method="post" action="login.php">
    <p>Username
      <input name="you" type="text" id="you" />
  </p>
    <p>Password
      <input name="me" type="text" id="me" />
</p>
    <p>
      <input type="submit" name="Submit" value="Submit" />
      <input type="reset" name="Submit2" value="Reset" />
    </p>
  </form>
  <p>&nbsp;</p>
  <div align="center" class="style1"></div>
</div>
<?PHP
}
?>
</body>
</html>
can anyone tell me what i have done wrong (voided any of the if else statement rules?)

Posted: Wed May 31, 2006 5:34 pm
by Christopher
Ignoring all that HTML, your code is:

Code: Select all

if () {

...

}

...

else {

...

}
Maybe separating your code and HTML might help you.

Re: Unexpected T_ELSE Statement

Posted: Wed May 31, 2006 6:14 pm
by RobertGonzalez
Do this...

Code: Select all

<?php
session_start();
//simple check to see if the person is logged in
if($_SESSION['in'] != TRUE) {
echo 'You are not logged in,please log in at the admin area.';
?>
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
<html xmlns="http://www.w3.org/1999/xhtml">
<head>
<meta http-equiv="Content-Type" content="text/html; charset=iso-8859-1" />
<title>Admin Page</title>
<style type="text/css">
<!--
.style1 {font-size: 16px}
.style4 {font-size: 24px}
-->
</style>
</head>

<body>
<h1>
<?php
} else {
?>
</h1>
<div align="center" class="style1">
  <p class="style4"> Admin Login</p>
  <form id="form1" name="form1" method="post" action="login.php">
    <p>Username
      <input name="you" type="text" id="you" />
  </p>
    <p>Password
      <input name="me" type="text" id="me" />
</p>
    <p>
      <input type="submit" name="Submit" value="Submit" />
      <input type="reset" name="Submit2" value="Reset" />
    </p>
  </form>
  <p>&nbsp;</p>
  <div align="center" class="style1"></div>
</div>
<?php
}
?>
</body>
</html>

Posted: Wed May 31, 2006 6:42 pm
by a94060
so i guess it was probably a problem with my brackets?

Posted: Wed May 31, 2006 6:55 pm
by Christopher
a94060 wrote:so i guess it was probably a problem with my brackets?
Maybe this makes it clearer:

Code: Select all

if () {

} YOU HAVE TEXT HERE  else {

}
Again, maybe separating your code and HTML might help you.

Posted: Wed May 31, 2006 7:21 pm
by a94060
so,i had code outside of the brackets? I still dont seem to udnerstand (only 14) can u just tell me.

Posted: Wed May 31, 2006 7:38 pm
by Christopher
Yep ... with the control structures you need to put code between the { and } (or only have one code line).

Posted: Wed May 31, 2006 7:58 pm
by a94060
sorry... i did not seem to understand that i had garbage that was outside of the brackets. My fault