php - Can't submit values to database after changing html attributes -


i trying make password changing option in 1 of works.

what want is:
1. first verify current password.
2. if current password entered correct 'proceed' button shifts down , new field called 'confirm' displayed.
3. when displayed, attribute of fields , button changed.
4. want enter new password , confirm password in respective fileds , check whether both fields have same value.
5. if both have same value table updated , if not alert made.

problem: step 4, facing problem. whenever give wrong values in both fields, error 'incorrect password' , not 'password , confirm password not match!'.

where possibly going wrong?

thanks in advance.

jquery

<script> $(document).ready(function() {     $('#button1').click(function()     {         var password=$('#password').val();         var datastring = 'password='+password;         $.ajax({             type:"post",             data: datastring,             url: "activatesettings.php",             cache:false,             success: function(html){                 if(html){                     alert('incorrect password');                 }                 else{                     $('#password').attr('id', 'newpassword');                     $('#newpassword').attr('name', 'newpassword');                     $('#newpassword').val('');                     $('#newpassword').attr('placeholder', 'enter new password');                      $('#confirm').css("visibility", "visible");                      $('#button1').addclass('move');                     $('#button1').val('change');                     $('#button1').attr('id', 'buttonchange');                     $('#buttonchange').attr('name', 'buttonchange');                 }             }         });     });       $('#buttonchange').click(function()     {         var newpassword=$('#newpassword').val();         var confirmpassword = $('#confirm').val();          var datastring = 'newpassword='+newpassword+'&confirmpassword='+confirmpassword;          $.ajax({             type:"post",             data: datastring,             url: "activatesettings.php",             cache:false,             success: function(html){                 if(html){                     alert('password , confirm password not match!');                 }             }         });     }); }); </script> 

php

<?php include 'connect.php'; session_start();  if (isset($_post['password'])) {     $found = false;     $password = $_post['password'];     $user = $_session['username'];     $sql = "select salt, password, firstname, lastname user username = '$user'";     $result = mysqli_query($db, $sql);      if ($data = mysqli_fetch_array($result))     {         $salt = $data['salt'];         $crypt_pass = hash('sha256', $salt.$password);             if ($crypt_pass == $data['password'])             {                     $found = true;         }     }         mysqli_close($db);          if($found == false)         {         echo '0';     } } else if(isset($_post['newpassword']) && isset($_post['confirmpassword'])) {     $newpassword = $_post['newpassword'];         $confirmpass = $_post['confirmpassword'];      if($newpassword == $confirmpass)     {         //create salt         $bytes = openssl_random_pseudo_bytes(6, $cstrong);             $salt   = bin2hex($bytes);         //encrypt password salt         $crypt_pass = hash('sha256', $salt.$password);          $sql = "update `user` set `salt` = $salt, `password` = $crypt_pass `username` = '$user'";         $result = mysqli_query($db, $sql);             mysqli_close($db);     }     else{         echo '0';     } } ?> 

html

        <input type="password" id="password" name="password" value="" autocomplete="off" placeholder="enter current password">         <input type="password" id="confirm" name="confirm" value="" autocomplete="off" placeholder="re-type password">         <input type="submit" id="button1" name="proceed" value="proceed"> 

update: tried script given naresh. shows me proper messages no effect database made.

change script

<script> function check(val) {   var type=$(val).attr("name");     if(type=="proceed")     {         var password=$('#password').val();         var datastring = 'password='+password;         $.ajax({             type:"post",             data: datastring,             url: "test.php",             cache:false,             success: function(html){                 if(html=="false"){                     alert('incorrect password');                 }                 else{                      $('#password').attr('id', 'newpassword');                     $('#newpassword').attr('name', 'newpassword');                     $('#newpassword').val('');                     $('#newpassword').attr('placeholder', 'enter new password');                      $('#confirm').css("visibility", "visible");                      $('#button1').addclass('move');                     $('#button1').val('change');                     $('#button1').attr('id', 'buttonchange');                     $('#buttonchange').attr('name', 'buttonchange');                 }             }         });     }     else if(type=="buttonchange")     {         var newpassword=$('#newpassword').val();         var confirmpassword = $('#confirm').val();          var datastring = 'newpassword='+newpassword+'&confirmpassword='+confirmpassword;          $.ajax({             type:"post",             data: datastring,             url: "test.php",             cache:false,             success: function(html){                  if(html=="false"){                     alert('password , confirm password not match!');                 }             }         });     } } </script> 

change button to

<input type="submit" id="button1" name="proceed" value="proceed" onclick="check(this)">  

php

<?php //include 'connect.php'; session_start();  if (isset($_post['password'])) {     $found = false;     $password = $_post['password']; //    $user = $_session['username'];       if( $password=="test")     {         echo "true";     }     else         echo "false"; } else if(isset($_post['newpassword']) && isset($_post['confirmpassword'])) {     $newpassword = $_post['newpassword'];         $confirmpass = $_post['confirmpassword'];      if($newpassword == $confirmpass)     {         echo "true";     }     else{        echo "false";     } } ?> 

Comments

Popular posts from this blog

Java 3D LWJGL collision -

spring - SubProtocolWebSocketHandler - No handlers -

methods - python can't use function in submodule -