2012-07-07 273 views
0

我正在讓一個系統來更改我的密碼,我不知道爲什麼我得到這個錯誤。 我有這樣的錯誤消息:爲什麼會出現此錯誤?解析錯誤:語法錯誤,意外T_ELSE

Parse error: syntax error, unexpected T_ELSE in /home/zenonhos/public_html/system/changepass.php on line 37

<?php 
session_start(); 

$user = $_SESSION['username']; 

if ($user) 
{ 

    if ($_POST['submit']) 
    { 
     $oldpassword = md5($_POST['oldpassword']); 
     $newpassword = md5($_POST['newpassword']); 
     $repeatnewpassword = md5($_POST['repeatnewpassword']); 


     $connect = mysql_connect("*******","******","*****"); 
     mysql_select_db("zenonhos_lr"); 

     $queryget = mysql_query("SELECT `password` FROM `users` WHERE username='$user'") or die(); 
     $row = mysql_fetch_assoc($queryget); 
     $oldpassworddb = $row['password']; 

     if ($oldpassword==$oldpassworddb) 
     { 
      if ($newpassword == "") { 
       echo "Password cannot be blank"; 
      } else { 

       if ($newpassword==$repeatnewpassword) 
       { 
        $querychange = mysql_query("UPDATE `users` SET password='$newpassword' WHERE username='$user'"); 

        session_destroy(); 
        die("Password successfully changed! <a href='index.php'>Return to home page</a>"); 
       } else { 
        die("New passwords do not match"); 
       } else { 
        die("Old password does not match"); 
       } echo "<form action='changepass.php' method='POST'> 
        Old Password: <input type='password' name='oldpassword'><br> 
        New Password: <input type='password' name='newpassword'><br> 
        Repeat New Password: <input type='password' name='repeatnewpassword'><br> 
        <input type='submit' name='submit' value='Change Password'>"; 
      } else { 
       die("You must be logged in to view this page."); 
      } 

?> 
+2

請閱讀:http://en.wikipedia.org/wiki/Indentation – Jack 2012-07-07 05:48:53

+0

嗯你可以使用2個連續的? 「else else {」New passwords do not match「); } else {」 – 2012-07-07 05:53:12

+0

@Shadow_boi是正確的,我認爲(你應該提交作爲答案:-) – 2012-07-07 06:00:37

回答

0

你錯過了樹},並有兩個sintax錯誤,因爲兩個else。以下是您的代碼更新。

$user = $_SESSION['username']; 

if ($user) 
{ 
    if ($_POST['submit']) 
    { 
     $oldpassword = md5($_POST['oldpassword']); 
     $newpassword = md5($_POST['newpassword']); 
     $repeatnewpassword = md5($_POST['repeatnewpassword']); 

     $connect = mysql_connect("*******","******","*****"); 
     mysql_select_db("zenonhos_lr"); 

     $queryget = mysql_query("SELECT `password` FROM `users` WHERE username='$user'") or die(); 
     $row = mysql_fetch_assoc($queryget); 
     $oldpassworddb = $row['password']; 

     if ($oldpassword==$oldpassworddb) 
     { 
      if ($newpassword == "") 
      { 
       echo "Password cannot be blank"; 
      } 
      else 
      { 

       if ($newpassword==$repeatnewpassword) 
       { 
        $querychange = mysql_query("UPDATE `users` SET password='$newpassword' WHERE username='$user'"); 

        session_destroy(); 
        die("Password successfully changed! <a href='index.php'>Return to home page</a>"); 
       } 
       else 
       { 
        die("Old password does not match"); 
       } 
      } 
     } 
    } 
} 

echo " 
    <form action='changepass.php' method='POST'> 
    Old Password: <input type='password' name='oldpassword'><br> 
    New Password: <input type='password' name='newpassword'><br> 
    Repeat New Password: <input type='password' name='repeatnewpassword'><br> 
    <input type='submit' name='submit' value='Change Password'>"; 

?> 
+0

這仍然不起作用,只是給了我一個更低的線路上的錯誤 – 2012-07-07 06:03:08

+0

@JonathanSmith,請再次複製並粘貼代碼,我做了一些更改。如果你得到錯誤,把它們放在這裏。 – 2012-07-07 06:06:28

+0

現在它甚至沒有顯示窗體,也沒有錯誤 – 2012-07-07 06:09:30

0

您還沒有關閉這個if語句的括號:

if ($user) 
{ 

if ($_POST['submit']) 
{ 
if ($oldpassword==$oldpassworddb) 
{ 

爲了解決這個問題,只是在年底將有} } }它們關閉的源代碼。

此外,我建議您強烈閱讀this

相關問題