语法错误,意外'否则' (T_ELSE)

时间:2016-01-22 01:45:13

标签: php mysql html5

我正在编写一个带有MySQL数据库的基本登录系统,我遇到了这个问题。有解决方案吗这也是一个现实问题。如果您去OcelaRealms.com/proxy并尝试登录,则会收到此错误,"解析错误:语法错误,意外情况'否则' (T_ELSE)在第40和34行的C:\ xampp \ htdocs \ proxy \ login.php中;

这是我的代码:

<?php

session_start();

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

if ($username&&$password)
{

         $connect =  mysql_connect("192.168.1.19","root","xxx") or die ("Couldnt connect to MySQL database. Please contact Ocela at dylplum2002@gmail.com");
         mysql_select_db("proxy") or die ("Couldn't find database. Please contact Ocela at dylplum2002@gmail.com");

         $query = mysql_query("SELECT * FROM users WHERE username='$username'");

         $numrows = mysql_num_rows($query);

         if($numrows !=0)

         {

         while ($row = mysql_fetch_assoc($query))
         {

            $dbusername = $row['username'];
            $dbpassword = $row['password'];

         {
            if ($username==$dbusername&&$password==$dbpassword)
            {

               echo "Login succesful. <a href='/proxy/index.php'>Click here to enter the Premium Proxy.</a>";
               $_SESSION['username']=$dbusername;

            }
            else 
               echo "Incorrect password.";
         }

         else
            die "That login doesnt exist. To get an account please contact Dylan.";         


}
else
   die ("Please enter a username and password.");

?>

1 个答案:

答案 0 :(得分:1)

您已经在时间内添加了{而忘记为}添加if($numrows !=0)

<?php

session_start();

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

if ($username&&$password)
{

         $connect =  mysql_connect("192.168.1.19","root","xxx") or die ("Couldnt connect to MySQL database. Please contact Ocela at dylplum2002@gmail.com");
         mysql_select_db("proxy") or die ("Couldn't find database. Please contact Ocela at dylplum2002@gmail.com");

         $query = mysql_query("SELECT * FROM users WHERE username='$username'");

         $numrows = mysql_num_rows($query);

         if($numrows !=0)

         {

             while ($row = mysql_fetch_assoc($query))
             {

                $dbusername = $row['username'];
                $dbpassword = $row['password'];


                if ($username==$dbusername&&$password==$dbpassword)
                {

                   echo "Login succesful. <a href='/proxy/index.php'>Click here to enter the Premium Proxy.</a>";
                   $_SESSION['username']=$dbusername;

                }
                else
                   echo "Incorrect password.";
             }

        }
         else
            die "That login doesnt exist. To get an account please contact Dylan.";        


}
else
   die ("Please enter a username and password.");

?>