javascript - AJAX to PHP to mySQL debugging -


i having trouble change password script website. using ajax connection php. database connection solid, , sending correct variables (according firebug), lost in translation guess. having trouble printing out error reports because theme covering them up. realize code isn't secure, , intend on changing that. right now, need getting code work. have been working on past 2 days now, , can't seem find niche.

here login page code included.

    <?php      include_once("php_includes/check_login_status.php");     ob_start();     error_reporting(e_all);     ini_set('display_error', 'on');     $isowner = "no";     if($user_ok == true){         $isowner = "yes";         $u = $_session['username'];     } else {         header("location: http://www.ibnwmo.com");     } ?> <?php // ajax calls code execute if(isset($_post['u'])) {     include_once("php_includes/db_conx.php");     $username = '';     $oldpasshash = '';     $newpasshash = '';     $username = preg_replace('#[^a-z0-9]#i', '', $_post['u']);     var_dump($username);     $oldpasshash = md5($_post["cp"]);     $newpasshash = md5($_post["cnp"]);     $sql = "select id, username, password users username='$username' limit 1";     $query = mysqli_query($db_conx, $sql);     $row = mysqli_fetch_row($query);     $db_id = $row["0"];     $db_username = $row["1"];     $db_password = $row["2"];     $dump = var_dump($cnp);     $dump2 = var_dump($cp);     if($db_password != $oldpasshash){         echo "no_exist";         exit();     } else {         $sql = "update users set password='$newpasshash', username='$db_username' limit 1";         $query = mysqli_query($db_conx, $sql);     }     $sql = "select id, username, password users username='$db_username' limit 1";     $query = mysqli_query($db_conx, $sql);     $row = mysqli_fetch_row($query);     $db_newpass = $row[3];     if($db_newpass == $newpasshash) {     echo "success";     exit();     } else {         echo "pass_failed";         exit();     } } ?> <!doctype html> <html> <head> <meta charset="utf-8"> <title>forgot password</title> <link rel="icon" href="images/favicon.ico" type="image/x-icon"> <link rel="stylesheet" href="css/mainstyle.css"> <script src="js/main.js"></script> <script src="js/ajax.js"></script> <script> function changepass() { var u = _("username").value;  var cp = _("currentpass").value;  var np = _("newpass").value;  var cnp = _("confirmnewpass").value;  if(np != cnp) {     _("status").innerhtml = "the passwords given not match!";     } else if (cp === "" || np === "" || cnp === "") {         _("status").innerhtml = "please fill out of fields.";     } else {         _("changepassbtn").style.display = "none";         _("status").innerhtml = 'please wait ...';         var ajax = ajaxobj("post", "change_password.php");         ajax.onreadystatechange = function() {         if(ajaxreturn(ajax) === true) {         var response = ajax.responsetext;        if(response == "success") {           _("status").innerhtml = '<h3>your password has been changed!</p>';         } else if (response == "no_exist") {           _("status").innerhtml = "sorry, current password entered incorrectly.";           _("changepassbtn").style.display = "initial";         } else if (response == "pass_failed") {             _("status").innerhtml = "sorry, password change failed.";             _("changepassbtn").style.display = "initial";         } else {             _("status").innerhtml = "an unknown error occurred";             _("changepassbtn").style.display = "initial";         }       }     };     ajax.send("u="+u+"&cp="+cp+"&np="+np+"&cnp"+cnp);     } } </script> 

if front end submitting values expect, can continue debugging php code logging statements, i.e. in change_password.php:

error_log(date('ymdhis').": ".print_r($_request,true)."\n", 3, '/tmp/change_password.log');


Comments

Popular posts from this blog

javascript - RequestAnimationFrame not working when exiting fullscreen switching space on Safari -

Python ctypes access violation with const pointer arguments -