-2

我正在尝试在我的网站上添加更改密码功能。我决定尝试使用 ajax,这样网站就不必自行更新了。但我有一个问题。当我将表单提交到我的 PHP 文件时,什么都没有发生,我只是从 ajax 文件中获得了成功。我的 SQL 数据库中的密码没有更改。

这是html文件。

<div class="boxPW">
                        <div class="boxInner">
                         <a href="#"><img class="closeBox" style="float: right;" src="images2/zoom/closebox.png" /></a>
                           <h2>Endre passord ditt</h2>

                           <div id="lineBreak" style="margin-top: -19px; width: 70%;"></div>

                           <h4>Skriv inn et nytt passord for <?php echo $fname.' '.$lname.' ';?>
                           Vi anbefaler at du oppretter et unikt passord – 
                           et du ikke bruker på noen andre nettsteder. <h4>
                           <div class="boxInner2">
                                <form id="changePw" name="changePw" method="POST" action="">                                                                           
                                   <input type="password" id="oldPw" name="oldPw" placeholder="Nåværende passord"  />
                                   <label id="error_oldPw" class="error">Fyll inn nåværende passord</label>
                                   <p style="margin: 0; width:100px; font-size:9px; color: #38C6DA; ">Glemt ditt passord?</p>
                                   <div class="divider"></div>
                                   <input type="password" id="newPw" name="newPw" placeholder="Nytt passord"/>
                                   <label id="error_newPw" class="error">Fyll inn nytt passord</label>
                                   <div class="divider"></div>
                                   <input type="password" id="conNewPw" name="conNewPw" placeholder="Bekreft nytt passord"/>
                                   <label id="error_conNewPw" class="error">Gjenta ditt passord</label>
                                   <div class="divider"></div>
                                   <input id="buttonpw" class="button" type="button" name="submit" value="Endre passord" />   
                               </form>


                           </div>
                        </div>  
                   </div>

这是我的 Jquery 文件(returnPwBox.js)

$(document).ready(function() {
    $('.error').hide();
    $('#buttonpw').click(function(){
        //Validate inputData

        $('error').hide();
            var oldPw = $("input#oldPw").val();
                if(oldPw == ""){
                    $("label#error_oldPw").show();
                    $("input#oldPw").focus();
                    return false;
                    }
            var newPw = $("input#newPw").val();
                if(newPw == ""){
                    $("label#error_newPw").show();
                    $("input#newPw").focus();
                    return false; 
                    }
            var conNewPw = $("input#conNewPw").val();
                if(conNewPw != newPw){
                    $("label#error_conNewPw").show();
                    $("input#conNewPw").focus();
                    return false;
                    }

                    var dataString = 'oldpw='+ oldPw + '&newPw=' + newPw + '&conNewPw=' + conNewPw;

                    $.ajax({
                    type: "POST",
                    url: "changePw.php",
                    data: dataString,
                    success: function(){
                        $('.boxInner2').html("<div id='message' style='width: 300px;'></div");
                        $('#message').html("<h2>Endring fullført</h2>")
                        .append("<h4>Ditt passord er nå endret</h44>")
                        .hide()
                        .fadeIn(1000, function(){
                            $('#message').append("<img id='checkmark' src='imgaes2/pitcharrow.gif'/>");
                        });
                    }
                });
        return false;           
    });

这是我的changePw.php:

    <?php
    include('conn.php');
    require_once('auth.php');
    include('fetchMemData.php');


function clean($str){
    $str=@trim($str);
    if(get_magic_quotes_gpc());{

        $str = stripslashes($str);
        }
        return mysql_real_escape_string($str);
    }

$id=$_SESSION['SESS_MEMBER_ID'];
$oldPw = clean($_POST['oldPw']);
$newPw = clean($_POST['newPw']);
$conNewPw = clean($_POST['conNewPw']);

$oldPw = strip_tags($oldPw);
$newPw = strip_tags($newPw);
$conNewPw = strip_tags($conNewPw);

$oldPw = md5($oldPw);
$newPw = md5($newPw);
$conNewPw = md5($conNewPw);

if($oldPw == $password)
    {
        mysql_query("UPDATE reguser SET password='$newPw' WHERE mem_id='$id'");
    }else{
    echo ("Feil nåværende passord");
    }



?>

如果有人看到任何错误或任何建议,请大声疾呼!我需要一些帮助:)

4

1 回答 1

1

根据您编写的代码,未分配 $password 值(除非您在另一个文件中执行此操作),因此 $password 为 NULL ,并且 if:

if($oldPw == $password)
{
    mysql_query("UPDATE reguser SET password='$newPw' WHERE mem_id='$id'");
}else{
echo ("Feil nåværende passord");
}

返回假

于 2013-10-06T15:08:53.933 回答