Jump to content

[SOLVED] Unexpected T_ELSE (yes, I googled it)


Clinton

Recommended Posts

unexpected T_ELSE. Any ideas? (I /// HERE HERE /// the code in question)

 

 

 

<?php
/// LOGIN START ///
/// CHECK TO SEE IF USER IS LOGGED IN ///

if($_SESSION['logged_in'] == TRUE)
{
$query = mysql_query('SELECT prefix, lname FROM employers WHERE id = "'.mysql_real_escape_string($_SESSION['user_id']).'"');
         $row = mysql_fetch_assoc($query);
         extract($row);
?>

<div class="module_s2">
<div class="first">
<div class="sec">
<h2><? echo $prefix; echo $lname; ?></h2>
<div class="box-indent">
<div class="width">

Welcome back. You have the con.<br /> 
<p> <a href="logout.php">Logout</a> </p>

</div>
</div>
</div>
</div>
</div>

<?php }

/// IF USER IS NOT LOGGED IN THEN CHECK TO SEE IF FORM IS SUBMITTED ///

elseif (isset($_POST['login']))
{
	if($_POST['username']!='' && $_POST['password']!='')
	{
		$query = mysql_query('SELECT id, username, active FROM users WHERE username = "'.mysql_real_escape_string($_POST['username']).'" AND password = "'.mysql_real_escape_string(md5($_POST['password'])).'"');

		if(mysql_num_rows($query) == 1)
		{
    			$row = mysql_fetch_assoc($query);
			if($row['active'] == NULL)
			{
				$_SESSION['user_id'] = $row['id'];
				$_SESSION['logged_in'] = TRUE;
				header("Location: index.php");
			}
?>
echo "<div class='module_s2'>";
echo "<div class='first'>";
echo "<div class='sec'>";
echo "<h3>Login</h3>";
echo "<div class='box-indent'>";
echo "<div class='width'>";

<?php
/// HERE HERE HERE HERE ///			else {
				$error = 'Your membership was not activated. Please open the email that we sent and click on the activation link';
				}
		}
		else {
			$error = 'Login failed !';
		}
	}
	else 	{
		$error = 'Please user both your username and password to access your account';
			}
}
?>

<form action="<?=$_SERVER['PHP_SELF']?>" method="post" name="login" class="form-login">

<label> Username  </label> <input type="text" name="username" class="inputbox"/>
<input type="text" name="username" class="inputbox"/>
<label> Password  </label> <input type="password" name="password" class="inputbox"  /><br />
<input type="checkbox" name="remember" class="checkbox" value="yes" />
<label class="remember">  Remember Me  </label>
<input type="submit" name="login" class="button" value="login" />
<p> <a href="passwordreset.php"> Forgot your password? </a></p>
<p> <a href="usernamefind.php"> Forgot your username?</a> </p>
<p> No Account Yet? <a href="register.php"><br />
Create an account</a> </p>
</form>
</div>
</div>
</div>
</div>
</div>

<?php else { ?>


echo "<div class='module_s2'>";
echo "<div class='first'>";
echo "<div class='sec'>";
echo "<h3>Login</h3>";
echo "<div class='box-indent'>";
echo "<div class='width'>";
<form action="<?=$_SERVER['PHP_SELF']?>" method="post" name="login" class="form-login">

<label> Username  </label> <input type="text" name="username" class="inputbox"/>
<input type="text" name="username" class="inputbox"/>
<label> Password  </label> <input type="password" name="password" class="inputbox"  /><br />
<input type="checkbox" name="remember" class="checkbox" value="yes" />
<label class="remember">  Remember Me  </label>
<input type="submit" name="login" class="button" value="login" />
<p> <a href="passwordreset.php"> Forgot your password? </a></p>
<p> <a href="usernamefind.php"> Forgot your username?</a> </p>
<p> No Account Yet? <a href="register.php"><br />
Create an account</a> </p>
</form>
</div>
</div>
</div>
</div>
</div>

<?php } ?>

<?php /////END LOGIN//// ?>

Link to comment
Share on other sites

Change

 

else {

 

to

 

} else {

 

In your ///HERE HERE HERE HERE/// line

 

 

[edit]

 

Or myabe not... It seems ok, when I pasted it into my editor

 

But man...

 

You've got some php outside php tags just above this line

Link to comment
Share on other sites

You can't have code in between the closing brace of an if and the start of an else statement.  Example:

 

<?php
if (1 == 1) {
  print "One = one, that's good...\n";
}
?>
Just some random output, like your random HTML...
<?php
else {

Error:

Parse error: syntax error, unexpected T_ELSE in /home/nick/- on line 8

Link to comment
Share on other sites

Ok, so I changed everything in between brackets but I can't get this to work properly. This form submits to itself. So, if the user come to the website it displays the login form (the third step in the script). If they submit the form but are currently not logged in they go to the second step. I had to take out header("Location: index.php"); because they were already being called. Then if the index.php page is called and they are logged in it is supposed to show them being logged in and the login box is supposed to disappear.

 

Well...

 

1) It pulls up the page just fine if somebody is not logged in.

2) If I try to log in with my username only I get no errors. It looks like I just didn't do anything.

3) If I enter my username and password it doesn't find any rows so I get an extract row error but it does show the logged in portion of the script.

 

Should I just use a seperate login.php form to submit this too instead of submitting form to self? Would that solve these problems?

 

<?php }

/// IF USER IS NOT LOGGED IN THEN CHECK TO SEE IF FORM IS SUBMITTED ///

elseif (isset($_POST['login']))
{
	if($_POST['username']!='' && $_POST['password']!='')
	{
		$query = mysql_query('SELECT id, username, active FROM users WHERE username = "'.mysql_real_escape_string($_POST['username']).'" AND password = "'.mysql_real_escape_string(md5($_POST['password'])).'"');

		if(mysql_num_rows($query) == 1)
		{
    			$row = mysql_fetch_assoc($query);
			if($row['active'] == NULL)
			{
				$_SESSION['user_id'] = $row['id'];
				$_SESSION['logged_in'] = TRUE;
				}else {
			$error = 'Your membership was not activated. Please open the email that we sent and click on the activation link';
				}
		}
		else {
			$error = 'Login failed !';
		}
	}
	else 	{
		$error = 'Please user both your username and password to access your account';
			}

?>

<div class='module_s2'>
<div class='first'>
<div class='sec'>
<h3>Login</h3>
<div class='box-indent'>
<div class='width'>
<form action="<?=$_SERVER['PHP_SELF']?>" method="post" name="login" class="form-login">

<label> Username  </label> <input type="text" name="username" class="inputbox"/>
<label> Password  </label> <input type="password" name="password" class="inputbox"  /><br />
<input type="checkbox" name="remember" class="checkbox" value="yes" />
<label class="remember">  Remember Me  </label>
<input type="submit" name="login" class="button" value="login" />
<p> <a href="passwordreset.php"> Forgot your password? </a></p>
<p> <a href="usernamefind.php"> Forgot your username?</a> </p>
<p> No Account Yet? <a href="register.php"><br />
Create an account</a> </p>
</form>
</div>
</div>
</div>
</div>
</div>

<?php } else { ?>


<div class='module_s2'>
<div class='first'>
<div class='sec'>
<h3>Login</h3>
<div class='box-indent'>
<div class='width'>
<form action="<?=$_SERVER['PHP_SELF']?>" method="post" name="login" class="form-login">

<label> Username  </label> <input type="text" name="username" class="inputbox"/>
<label> Password  </label> <input type="password" name="password" class="inputbox"  /><br />
<input type="checkbox" name="remember" class="checkbox" value="yes" />
<label class="remember">  Remember Me  </label>
<input type="submit" name="login" class="button" value="login" />
<p> <a href="passwordreset.php"> Forgot your password? </a></p>
<p> <a href="usernamefind.php"> Forgot your username?</a> </p>
<p> No Account Yet? <a href="register.php"><br />
Create an account</a> </p>
</form>
</div>
</div>
</div>
</div>
</div>

<?php } ?>

<?php /////END LOGIN//// ?>

Link to comment
Share on other sites

This thread is more than a year old. Please don't revive it unless you have something important to add.

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.

Guest
Reply to this topic...

×   Pasted as rich text.   Restore formatting

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

×
×
  • Create New...

Important Information

We have placed cookies on your device to help make this website better. You can adjust your cookie settings, otherwise we'll assume you're okay to continue.