ajax и php обработчик находятся на одной странице, послать запрос через ajax?
<?php
session_start();
require_once "app_config.php";
require_once "checklogin.php";
$connect = @mysqli_connect(DB_HOST, DB_USERNAME, DB_PASSWORD, DB_NAME)
or handle_error("Ошибка подключения к базе данных", mysqli_connect_error());
mysqli_set_charset($connect, 'utf8');
$submit = $_POST['submit'];
if(!empty($submit)) {
$action = mysqli_real_escape_string($connect, trim($_POST['act']));
$oldpass = mysqli_real_escape_string($connect, trim($_POST['oldpass']));
$newpass = mysqli_real_escape_string($connect, trim($_POST['newpass']));
$confpass = mysqli_real_escape_string($connect, trim($_POST['confpass']));
$newmail = mysqli_real_escape_string($connect, trim($_POST['newmail']));
$pass = mysqli_real_escape_string($connect, trim($_POST['pass']));
$user_id = $_SESSION['user_id'];
$email = $_SESSION['email'];
$password = $_SESSION['password'];
if($action == 'pass') {
if($newpass == $confpass) {
$query = "SELECT COUNT(*) FROM users WHERE (user_id='$user_id') and (email='$email') and (password=SHA('$oldpass'))";
$result = mysqli_query($connect, $query);
$result = mysqli_fetch_array($result);
if($result[0] == "1") {
if(strlen($oldpass) >= 8) {
$query = "UPDATE users SET password = SHA('$newpass') WHERE (user_id='$user_id') and (email='$email') and (password=SHA('$oldpass'))";
$result = mysqli_query($connect, $query);
header("Location: logout.php");
} else {
echo "Пароль должен состоять как минимум из 8 символов";
}
} else {
echo "Неверный пароль";
}
} else {
echo "Пароли не совпадают";
}
}
?>
<!DOCTYPE html>
<html lang="en">
<head>
<meta charset="UTF-8">
<title><?=SITENAME ?> | Ваш аккаунт</title>
</head>
<body>
<h2>Изменение пароля</h2>
<div id="result_pass_edit"></div>
<form action="" method="post" id="pass_edit_form">
<label for="oldpass">Старый пароль</label>
<input type="password" name="oldpass" class="pass"><br>
<label for="newpass">Новый пароль</label>
<input type="password" name="newpass" class="pass_new_1"><br>
<label for="confpass">Повторите пароль</label>
<input type="password" name="confpass" class="pass_new_2"><br>
<input type="submit" name="submit" class="pass_edit" value="Сохранить пароль">
<input type="hidden" value="pass" name="act" >
</form>
<script src="site/js/jquery-2.1.1.js"></script>
<script type="text/javascript">
//ВХОД
$(document).ready(function(){
$.ajax({//аякс запрос
type: "POST",//тип передачи данных
url: "Сдесь ступор",
dataType: 'text',
data: $("#pass_edit_form").serialize(),//передаем данные
success: function(data) {//принимаем данные
console.log('Received: '+data);
if(data.length > 0) {
$('#result_pass_edit').text(data);
} else {
$('#result_pass_edit').text(data);
}
}
});
}
});
});
</script>
</body>
</html>