-6

I have written this code for my login page..!! the issue is this it is giving syntax error unexpected $end on line 89 which is last line of my code. i have tried all available solutions but nothing happened. the variables and queries are just fine i have checked them thoroughly . P.S. i am using notepad++ IDE so syntax error is minimum (*brackets open close). Thanks in advance.!!!!

  <?php session_start();
if(isset($_COOKIE["usNick"]) && isset($_COOKIE["usPass"])){ ?>
    <META HTTP-EQUIV="REFRESH" CONTENT="0;URL=myaccount.php">
<?php 
    exit();
}

$display_error = "";
$username = "";

if ($_POST['username']) {
    $username = $_POST['username'];
    if( strtolower($_POST['code'])!= strtolower($_SESSION['texto'])){ 
        $display_error = "* Security Code Error"; // error language
        include ('error.php');
        exit();
    }else{
        include('includes/config.inc.php');
        $username=uc($_POST['username']);
        $pass=uc($_POST['password']);
        $password = sha1($pass);

        if ($password==NULL) {
            $display_error = "* All fields are required"; // error language
            include ('error.php');
            exit();
        }else{
            $myDb->connect();
                $query = mysql_query("SELECT username,password FROM yob_users WHERE username = '$username'") or die(mysql_error());
                $data = mysql_fetch_array($query);
            $myDb->close();
            if($data['password'] != $password) {
                $display_error = "* Please, Check your username/password."; // error language
                include ('error.php');
                exit();
            }else{
                $myDb->connect();
                    $query = mysql_query("SELECT username,password FROM yob_users WHERE username = '$username'") or die(mysql_error());
                    $row = mysql_fetch_array($query);
                $myDb->close();
                $nicke=$row['username'];
                $passe=$row['password'];
                setcookie("usNick",$nicke,time()+7776000);
                setcookie("usPass",$passe,time()+7776000);
                $lastlogdate = date("F j, Y - g:i a");
                $lastip = getRealIP();
                $myDb->connect();
                    $querybt = "UPDATE yob_users SET lastlogdate='$lastlogdate', lastiplog='$lastip' WHERE username='$nicke'";
                    mysql_query($querybt) or die(mysql_error());
                $myDb->close(); ?> 
                <META HTTP-EQUIV="REFRESH" CONTENT="0;URL=myaccount.php">
<?
            }
        }
    }
}else{ 
    include ('header.php'); 
?>
        <div id="content">
            <p class="error"><?php echo $display_error;?></p>

          <form action="login.php" method="post" class="f-wrap-1">
          <div class="req"><a href="signup.php">Not Registered?</a><br /><a href="recoverpass.php">Forgot your Password?</a></div>
          <fieldset>

          <h3>Member Login</h3>

            <label for="firstname"><b>Username:</b>
            <input id="username" name="username" type="text" class="f-name" autocomplete="off" tabindex="1" /><br />
            </label>
            <label for="password"><b>Password:</b>
            <input id="password" name="password" type="password" class="f-name" autocomplete="off" tabindex="2" /><br />
            </label>
            <label for="code"><b>Security Code:</b>
            <input id="code" name="code" type="text" class="f-name" autocomplete="off" tabindex="3" /><br />
            </label>
            <label for="code2"><b>&nbsp;</b>
            <img src="image.php?<?php echo $res; ?>" /><br />
            </label>
            <div class="f-submit-wrap">
            <input type="submit" value="Submit" class="f-submit" tabindex="4" /><br />
            </div>
            </fieldset>
            </form>
        </div>
<?php
include ('footer.php'); 
}
?>
Rj Rana
  • 48
  • 12
  • 4
    Make sure you have all of your closing brackets. You almost certainly do not. – John Conde Oct 06 '14 at 19:37
  • 2
    Please, [don't use `mysql_*` functions](http://stackoverflow.com/questions/12859942/why-shouldnt-i-use-mysql-functions-in-php). *They are no longer maintained and are [officially deprecated](https://wiki.php.net/rfc/mysql_deprecation)*. Learn about [prepared statements](http://en.wikipedia.org/wiki/Prepared_statement) instead, and use [PDO](http://us1.php.net/pdo) or [MySQLi](http://us1.php.net/mysqli). [This article](http://php.net/manual/en/mysqlinfo.api.choosing.php) will help you decide. – Jay Blanchard Oct 06 '14 at 19:37
  • That's why nesting too deep is called bad practice. – Daniel W. Oct 06 '14 at 19:38
  • notepad++ is *not* an IDE... – admdrew Oct 06 '14 at 19:38
  • 1
    You are vulnerable to [sql injection attacks](http://bobby-tables.com). – Marc B Oct 06 '14 at 19:38
  • cutting and pasting your code (And commenting out the includes) and linting it ( php -l) shows that it is fine. My guess is that you have errors somewhere in your include files or in something you are not showing. – Doon Oct 06 '14 at 19:40
  • Notepad may not be an IDE, but it can still show you unmatched pairs of braces – Mark Baker Oct 06 '14 at 19:41
  • Doon i have done this before and it shows no syntax error....!!! – Rj Rana Oct 06 '14 at 19:42
  • jay i have done this also but nothing happened – Rj Rana Oct 06 '14 at 19:43
  • can you guys plz be more specific of problem. i am not getting it right – Rj Rana Oct 06 '14 at 19:45
  • 3
    My guess is this. You have a `` tag. Not having short open tags set/on, will cause that. So change it to ` – Funk Forty Niner Oct 06 '14 at 19:47

1 Answers1

1

You have a <? tag on line 52 of your posted code.

That is short tag syntax. Not having short open tags set/on, will cause that error.

So change it to <?php and you should be good to go.


  • An insight.

Should you later decide to use <?=
That is also short tag syntax which is equivalent to <?php echo in PHP.

Again, if short tags are not set, that would need to be <?php echo, .

Should there be any other <? tags, change them all to <?php.


To read up on how to enable short tags, visit this Q&A on Stack:


Footnotes:

Make sure your included files also do not contain short tags.

Community
  • 1
  • 1
Funk Forty Niner
  • 74,450
  • 15
  • 68
  • 141
  • i have applied your solution to login.php file header and footer files not contain any of this short code.. but nothing happened the error is still there.. can you run this code without including header and footer . plz its urgent..!! – Rj Rana Oct 07 '14 at 10:06