javascript - Login add type in php code but not working calling ajax not working
问题描述
I want to add type-wise define the role but not working fine and nor error show related PHP. I think ajax error but I have no idea gatting error. I am sharing login image and after login error show image so please help me...
Ajax Script here code
$('document').ready(function() {
/* handling form validation */
$("#login-form").validate({
rules: {
password: {
required: true,
},
user_email: {
required: true,
email: true
},
},
messages: {
password:{
required: "please enter your password"
},
user_email: "please enter your email address",
},
submitHandler: submitForm
});
/* Handling login functionality */
function submitForm() {
var data = $("#login-form").serialize();
$.ajax({
type : 'POST',
url : 'login.php',
data : data,
beforeSend: function(){
$("#error").fadeOut();
$("#login_button").html('<span class="glyphicon glyphicon-transfer"></span> sending ...');
},
success : function(response){
if(response=="ok"){
$("#login_button").html('<img src="ajax-loader.gif" /> Signing In ...');
setTimeout(' window.location.href = "welcome.php"; ',4000);
} else {
$("#error").fadeIn(1000, function(){
$("#error").html('<div class="alert alert-danger"> <span class="glyphicon glyphicon-info-sign"></span> '+response+' !</div>');
$("#login_button").html('<span class="glyphicon glyphicon-log-in"></span> Sign In');
});
}
}
});
return false;
}
});
PHP code here
<?php
session_start();
include_once("setting/config.php");
if(isset($_POST['login_button'])) {
$user_email = trim($_POST['user_email']);
$user_password = trim($_POST['password']);
$sql = "SELECT uid, user, pass, type, email FROM users WHERE email='$user_email'";
$resultset = mysqli_query($conn, $sql) or die("database error:". mysqli_error($conn));
$row = mysqli_fetch_assoc($resultset);
$type = $row['type'];
if($row['pass']==$user_password){
$_SESSION['user_session'] = $row['uid'];
//-----------type------------------
$_SESSION['user_session'] = $row['uid'];
if( $type==1){
header("location: index.php");
}elseif($type==2){
header("location: admin.php");
}elseif($type==3){
header("location: user.php");
}
//-----------type------------------
} else {
echo "email or password does not exist."; // wrong details
}
}
?>
Login page
after login error show
解决方案
推荐阅读
- r - 根据另一列选择前 n 项数据框
- java - youtubeplayer 已发布,当我从 youtubeplayer 转到 youtube 并杀死 youtube 应用程序并返回我的应用程序时
- java - 如何从 GCP Appengine Standard - Spring Boot Application 访问 GCP Cloud SQL(MSQL) 数据库
- sql - 发现难以获得最大价值
- wpf - 当Shell使用Prism6 for WPF关闭所有相关ViewModel时,如何正确调用Dispose函数来清理资源?
- django - 如何使用 post_status django rest api 获取所有帖子?
- java - 从两个列表中删除重复项