2016-01-22 70 views
-2

我正在用MySQL數據庫編寫一個基本的登錄系統,並且遇到了這個問題。任何解決方案這也是一個現實問題。如果您訪問OcelaRealms.com/proxy並嘗試登錄,則會在第40行的C:\ xampp \ htdocs \ proxy \ login.php中出現「解析錯誤:語法錯誤,意外的其他」(T_ELSE)錯誤「語法錯誤,意外的'else'(T_ELSE)

這是我的代碼:

<?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 [email protected]"); 
     mysql_select_db("proxy") or die ("Couldn't find database. Please contact Ocela at [email protected]"); 

     $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."); 

?> 
+0

發佈您的代碼。爲每個代碼行縮進4個空格,或者使用編輯框頂部的{}按鈕 –

+0

您在第27行缺少「if」語句。 –

回答

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 [email protected]"); 
     mysql_select_db("proxy") or die ("Couldn't find database. Please contact Ocela at [email protected]"); 

     $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."); 

?> 
相關問題