我的account_settings.php上的SYNTAX错误

时间:2015-08-24 09:21:56

标签: php

我正在关注在线教程。问题是我得到了

  

语法错误意外T_ELSE PHP第二个空白区域。

我曾尝试使用notepad ++对PHP空白字体进行排序,但它并没有消失。目前正在使用PHP 8.错误可能来自何处?

这是我的account_settings.php页面:

<?php
include( "header inc.php" ); 
if (!$user) {

}
else
{
 die ("You must be logged in to view this page!");
}
?>
<?php
$senddata = @$_POST['senddata'];

//Password variables
  $old_password = mysqli_real_escape_string($mysqli,@$_POST['oldpassword']);
  $new_password = mysqli_real_escape_string($mysqli,@$_POST['newpassword']);
  $repeat_password = mysqli_real_escape_string($mysqli,@$_POST['newpassword2']);
if ($senddata) 
    //If the form is submitted..

     $password_query = $mysqli->query("SELECT * FROM users WHERE username='$user'");
  while ($row = mysqli_fetch_assoc($password_query)) {
        $db_password = $row['password'];

        //md5 the old password before we check if it matches
        $old_password_md5 = md5($old_password);

        //Check whether old password equals $db_password
        if ($old_password_md5 == $db_password) {
         //Continue Changing the users password ...
         //Check whether the 2 new passwords match
         if ($new_password == $repeat_password) {

            //md5 the new password before we add it to the database
            $new_password_md5 = md5($new_password);
           //Great! Update the users passwords!
           $password_update_query = $mysqli->query("UPDATE users SET password='$new_password_md5' WHERE username='$user'");
           echo "Success! Your password has been updated!"; 
           }
           }
           else
           {
            echo "Your two new passwords don't match!";
            }
            }
            else
            {
                echo "The old password is incorrect!";
                }
                }
                else
                {
                    echo "";
                    }

?>
<h2>Edit your Account Settings below</h2>
<hr /> 
<form action="account_settings.php" accept-charset="utf-8" method="post">
<p>CHANGE YOUR PASSWORD:</p> <br />
Your Old Password: <input type="text" name="oldpassword" id="oldpassword" size="40"><br />
Your New Password: <input type="text" name="newpassword" id="newpassword" size="40"><br />
Repeat Password  : <input type="text" name="newpassword2" id="newpassword2" size="40"><br />

<hr />
<p>UPDATE YOUR PROFILE INFO:</p> <br />
First Name: <input type="text" name="fname" id="fname" size="40" value="<? echo $db_first_name; ?>"><br />
Last Name: <input type="text" name="lname" id="lname" size="40" value="<? echo $db_last_name; ?>"><br />
About You: <textarea name="about you" id="about you" rows="7" cols="40"></textarea>

<hr />
<input type="submit" name="senddata" id="senddata" value="Update Information">
</form>  

2 个答案:

答案 0 :(得分:0)

if ($senddata){

$password_query = $mysqli->query("SELECT * FROM users WHERE username='$user'");
  while ($row = mysqli_fetch_assoc($password_query)) {

 } 

 else{ 
 }

最后,下面提到的其他没有IF

 }
               else
            {
                echo "";
                }

修正了它,试试这个:

    <?php
    include( "header inc.php" ); 
    if (!$user) {

    }
    else
    {
     die ("You must be logged in to view this page!");
    }
    ?>
    <?php
    $senddata = @$_POST['senddata'];

    //Password variables
      $old_password = mysqli_real_escape_string($mysqli,@$_POST['oldpassword']);
      $new_password = mysqli_real_escape_string($mysqli,@$_POST['newpassword']);
      $repeat_password = mysqli_real_escape_string($mysqli,@$_POST['newpassword2']);
    if ($senddata) {

        //If the form is submitted..

         $password_query = $mysqli->query("SELECT * FROM users WHERE username='$user'");
      while ($row = mysqli_fetch_assoc($password_query)) {
            $db_password = $row['password'];

            //md5 the old password before we check if it matches
            $old_password_md5 = md5($old_password);

            //Check whether old password equals $db_password
            if ($old_password_md5 == $db_password) {
             //Continue Changing the users password ...
             //Check whether the 2 new passwords match
             if ($new_password == $repeat_password) {

                //md5 the new password before we add it to the database
                $new_password_md5 = md5($new_password);
               //Great! Update the users passwords!
               $password_update_query = $mysqli->query("UPDATE users SET password='$new_password_md5' WHERE username='$user'");
               echo "Success! Your password has been updated!"; 
               }
               }
               else
               {
                echo "Your two new passwords don't match!";
                }
                }
    } 
                else
                {
                    echo "The old password is incorrect!";
                    }

    ?>
    <h2>Edit your Account Settings below</h2>
    <hr /> 
    <form action="account_settings.php" accept-charset="utf-8" method="post">
    <p>CHANGE YOUR PASSWORD:</p> <br />
    Your Old Password: <input type="text" name="oldpassword" id="oldpassword" size="40"><br />
    Your New Password: <input type="text" name="newpassword" id="newpassword" size="40"><br />
    Repeat Password  : <input type="text" name="newpassword2" id="newpassword2" size="40"><br />

    <hr />
    <p>UPDATE YOUR PROFILE INFO:</p> <br />
    First Name: <input type="text" name="fname" id="fname" size="40" value="<? echo $db_first_name; ?>"><br />
    Last Name: <input type="text" name="lname" id="lname" size="40" value="<? echo $db_last_name; ?>"><br />
    About You: <textarea name="about you" id="about you" rows="7" cols="40"></textarea>

    <hr />
    <input type="submit" name="senddata" id="senddata" value="Update Information">
    </form>  

答案 1 :(得分:-1)

语法错误在else条件下。

尝试

<?php
include ("header inc.php"); 
if (!$user)
{

}
else
{
    die ("You must be logged in to view this page!");
}

//Password variables
$old_password = mysqli_real_escape_string($mysqli,@$_POST['oldpassword']);
$new_password = mysqli_real_escape_string($mysqli,@$_POST['newpassword']);
$repeat_password = mysqli_real_escape_string($mysqli,@$_POST['newpassword2']);

if(isset($_POST['senddata'])) 
{
    //If the form is submitted..
    $password_query = $mysqli->query("SELECT * FROM users WHERE username='$user'");
    while ($row = mysqli_fetch_assoc($password_query))
    {
        $db_password = $row['password'];

        //md5 the old password before we check if it matches
        $old_password_md5 = md5($old_password);

        //Check whether old password equals $db_password
        if ($old_password_md5 == $db_password)
        {
         //Continue Changing the users password ...
         //Check whether the 2 new passwords match
            if ($new_password == $repeat_password)
            {
                //md5 the new password before we add it to the database
                $new_password_md5 = md5($new_password);
                //Great! Update the users passwords!
                $password_update_query = $mysqli->query("UPDATE users SET password='$new_password_md5' WHERE username='$user'");
                echo "Success! Your password has been updated!"; 
            }
            else
            {
                echo "Your two new passwords don't match!";
            }
        }
        else
        {
            echo "The old password is incorrect!";
        }
    }
}

?>
<h2>Edit your Account Settings below</h2>
<hr /> 
<form action="account_settings.php" accept-charset="utf-8" method="post">
<p>CHANGE YOUR PASSWORD:</p> <br />
Your Old Password: <input type="text" name="oldpassword" id="oldpassword" size="40"><br />
Your New Password: <input type="text" name="newpassword" id="newpassword" size="40"><br />
Repeat Password  : <input type="text" name="newpassword2" id="newpassword2" size="40"><br />

<hr />
<p>UPDATE YOUR PROFILE INFO:</p> <br />
First Name: <input type="text" name="fname" id="fname" size="40" value="<? echo $db_first_name; ?>"><br />
Last Name: <input type="text" name="lname" id="lname" size="40" value="<? echo $db_last_name; ?>"><br />
About You: <textarea name="about you" id="about you" rows="7" cols="40"></textarea>

<hr />
<input type="submit" name="senddata" id="senddata" value="Update Information">
</form>