<?php // Check not accessed directly. if (!isset($post_update)) { echo "Are you searching for something? You maybe in wrong place then!!"; return; } // Common Update Code for database $obj = new $_GET['master'](); $suc = $obj->set_assoc_array($_POST); //var_dump($suc); //var_dump($obj); if (Master::isLegit($suc)) { //Database Part $dbh = new MyDbCon(); $dbh->update($obj, array($id_mapping[$_GET['master']] => $queries['id']), $dontUpdateIds); $dbh->prepare(); $dbh->execute(); $final = sprintf("%s Updated Successfully!!", $_GET['master']::HEADING); echo json_encode(array("done" => true, "final" => $final)); } else { echo json_encode($suc); }
} try { $dbh = new MyDbCon(); $dbh->select("User_Master"); $dbh->select->where->equalTo("user_name", $_SESSION['user_name']); $dbh->prepare(); $dbh->execute(); $user = $dbh->fetchAll()[0]; if ($user->match_password($_POST['user_password_old'])) { $newUser = $user->get_assoc_array(); $newUser['user_password'] = $_POST['user_password']; $newUser['user_password1'] = $_POST['user_password1']; $nu = new User_Master(); $suc = $nu->set_assoc_array($newUser); if (Master::isLegit($suc)) { $dbh->update($nu, array("user_name" => $_SESSION['user_name'])); $dbh->prepare(); $dbh->execute(); $final = json_encode(array("done" => true, "final" => "Password Changed Successfully!")); header('Content-Length: ' . strlen($final)); header('Content-Type: application/json'); echo $final; } else { account_error(HTTP_Status::BAD_REQUEST, "Password do not match the given specification!!"); } } else { account_error(HTTP_Status::BAD_REQUEST, "Old Password do not match"); } } catch (\Exception $e) { $message = $e->getPrevious() ? $e->getPrevious()->getMessage() : $e->getMessage(); $code = $e->getPrevious() ? $e->getPrevious()->getCode() : $e->getCode();