-2

谢谢阅读。

提交表单后,在正确页面上回显错误时遇到问题。提交表单后,它会重定向到website.com/controllers/accountController.php。我希望它刷新当前页面website.com/play.php?p=myaccount

请注意,表单正在提交,它只是在重定向页面而不是带有表单的页面上打印错误。

请看一下我之前的问题(相关但完全不同的问题)。

HTML 表单(myaccount.inc.php):

<div id="change-password">

    <form class="clearfix" action="controllers/accountController.php" method="post">

        <div><span class="he1">Change Password</span></div>

        <div><label class="DEVON" for="password">Current Password:</label></div>
        <input type="password" name="password" id="password" size="23" /><br />

        <div><label class="DEVON" for="passwordnew1">New Password:</label></div>
        <input type="password" name="passwordnew1" id="passwordnew1" size="23" /><br />

        <div><label class="DEVON" for="passwordnew2">Confirm New Password:</label></div>
        <input type="password" name="passwordnew2" id="passwordnew2" size="23" /><br />

        <input type="submit" name="submit" value="Change Password" class="bt_changepass" />

    </form>

</div>

PHP 代码(accountController.php):

<?php

// Checking whether the Password Change form has been submitted.
if(isset($_POST['submit'])=='Change Password')
{
echo "<br />";

// Get the data from the database.
$sql = $mysqli->query("SELECT * FROM ss_members WHERE usr = '".$_SESSION['usr']."' AND pass = '".md5($_POST['password'])."'");

$row = $sql->fetch_assoc();

// Will hold our errors
$err = array();

if($_POST['password'] == "" || $_POST['passwordnew1'] == "" || $_POST['passwordnew2'] == "")
{
    $err[] = 'All the fields must be filled in!';
}

if(!$row['pass'] == md5($_POST['password']) && $_POST['passwordnew1'] != "" && $_POST['passwordnew2'] != "")
{
    $err[] = 'Current password is not correct!';
}

if($_POST['passwordnew1'] <> $_POST['passwordnew2'])
{
    $err[] = 'New passwords do not match!';
}

if(!count($err))
{
    if($row['usr'])
    {
        // If everything is OK change password.
        $stmt = $mysqli->prepare("UPDATE ss_members SET pass = md5(?) WHERE usr = {$_SESSION['usr']}");
        $stmt->bind_param('s', $_POST['passwordnew1']);
        $stmt->execute();
        $stmt->close();

        echo "Password has been sucessfully updated!<br />";
    }
    else
    {
        $err[]='Something broke!';
    }
}

if($err)
{
    // Save the error messages in the session.
    foreach($err as $error)
    {
        echo $error . "<br />";
    }   
}

echo "<br />";
}
4

3 回答 3

3

if(isset($_POST['submit'])=='Change Password')陈述是错误的。

因为isset总是返回Boolean所以你的 if 永远不会执行。

或者

您可以将其用作

if(isset($_POST['submit']) && $_POST['submit'] =='Change Password')
于 2013-03-01T06:46:45.040 回答
0
if(isset($_POST['submit'])=='Change Password')

isset 与更改密码比较时返回 true 或 false 将返回 false

问候。

于 2013-03-01T06:47:50.723 回答
0

if(isset($_POST['submit'])=='change Password') 这种用法在php中无效

于 2013-03-01T08:57:53.413 回答