jquery - How to submit a form with ajax and php -


i trying add change password function on site. decided try using ajax site not have update itself. have 1 problem. when submit form php file nothing happends success ajax file. , password not change in sql db.

this html file.

<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 <?php echo $fname.' '.$lname.' ';?>                            vi anbefaler @ 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> 

and here jquery file (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;                }); 

and here 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' mem_id='$id'");     }else{     echo ("feil nåværende passord");     }    ?> 

if see errors or suggestions, shout out! need help:)

based on code wrote $password value not asigned (unless did in file) therefore $password null , , if:

if($oldpw == $password) {     mysql_query("update reguser set password='$newpw' mem_id='$id'"); }else{ echo ("feil nåværende passord"); } 

returns false


Comments

Popular posts from this blog

java.util.scanner - How to read and add only numbers to array from a text file -

rewrite - Trouble with Wordpress multiple custom querystrings -