为什么这个错误?解析错误:语法错误,意外T_ELSE

时间:2012-07-07 05:46:11

标签: php

我正在制作一个更改密码的系统,我不知道为什么会收到此错误。 我有此错误消息:

  

解析错误:语法错误,第37行/home/zenonhos/public_html/system/changepass.php中的意外T_ELSE

<?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 个答案:

答案 0 :(得分:0)

您尚未关闭此if语句的括号:

if ($user)
{

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

要解决此问题,只需将} } }放在源代码的末尾即可关闭它们。

另外,我建议强烈阅读this

答案 1 :(得分:0)

您错过了树},由于有两个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'>";

?>