jquery ajax login form submit

AJAX LOGIN or FORM POST Ajax method form posting and login without page reload or refresh. 

Loginform.php


scipt.js
$("#logfrm").submit(function(){
   
    var email =$("#mail").val();
    if(email =='')
    {
    var email =$("#mob").val();
    }

   
    var password = $("#pwd").val();                       

//alert("asdf");
var dataString = 'email='+ email + '&password='+ password;
alert(dataString);
$.ajax({
type: "POST",
url: "class/login.php",
data: dataString,
cache: false,
success: function(result){
//alert(result);
 //$('#regfrm')[0].reset();//alert(result);
}
});
//}
//alert('ok');
window.location.href = "http://alayams.com/";
$('#logfrm')[0].reset();
return false;
});

login. php

require 'dbconnect.php';
session_start();
$email=$_POST['email'];
$password=$_POST['password'];
date_default_timezone_set('Asia/Kolkata');
//echo date('d-m-Y H:i');
 $today = date('d-m-Y H:i');

$sql="select * from user where password='$password' AND status = 1 AND (email='$email' OR mobile='$email')";
$result = $con->query($sql);
if ($result->num_rows > 0) {
// output data of each row
while($row = $result->fetch_assoc())

 {
  $_SESSION['email']=$row['email'];
  $_SESSION['name']=$row['fname'].' '.$row['lname'];
  echo "success";
 }
 }
else
 {
  echo "fail";
 }
 exit();

Share this

Related Posts

Previous
Next Post »

Pageviews from the past week