0

I want to convert this simple posting form into ajax posting form

I tried to do this but does could not do this please help me my code is given below

and i want to change it to ajax submit can you please help me

this is my login.php

session_start();
require_once 'class.user.php';
$user_login = new USER();
if($user_login->is_logged_in()!="")
{
$user_login->redirect('../mydrive/dashboard');
  }
 if(isset($_POST['btn-login']))
{
  $email = trim($_POST['txtemail']);
  $upass = trim($_POST['txtupass']);
    if($user_login->login($email,$upass))
{
$user_login->redirect('../mydrive/dashboard');
}
  }
?>

class.user.php function

public function login($email,$upass)
       {
        try
        {
$stmt = $this->conn->prepare("SELECT * FROM users 
WHERE email=:email_id");
            $stmt->execute(array(":email_id"=>$email));
            $userRow=$stmt->fetch(PDO::FETCH_ASSOC);

            if($stmt->rowCount() == 1)
            {
                if($userRow['userStatus']=="Y")
                {
                    $checkedupass = 
    $userRow['userPass'];

   if(password_verify($upass,$checkedupass))


                    {
            $_SESSION['userSession'] =  $userRow['id'];
                        return true;
                }
                else
                {

if user details are incorrect or not logged in or no account found:

    header("Location: login? 
   error=invalid_login");
   exit;
                }
            }
            else
            {
                header("Location: login? 
  error=inactive");
                    exit;
                }   
            }
            else
            {
                header("Location: login? 
   error=AccountNotFound");
            exit;
            }       
        }
        catch(PDOException $ex)
        {
            echo $ex->getMessage();
        }
    }
  • `$("form").on("submit",function(e) { e.preventDefault(); $.post("login.php",$(this).serialize(),function(res) { console.log(res); })` – mplungjan Jan 27 '19 at 07:45
  • sorry i did not understand can you have the gmail address i send you the code please then you edit that code please help me i am a junior developer of php – Salik Salman Jan 27 '19 at 07:58
  • You wanted the form to be ajaxed. The above code does that. Nothing much to explain. – mplungjan Jan 27 '19 at 08:04
  • Assuming your are using jQuery (becasue of your tag) - https://api.jquery.com/jquery.post/ there is more info on posting ajax with jQuery. If you want to do it without jQuery -https://stackoverflow.com/questions/8567114/how-to-make-an-ajax-call-without-jquery – Second2None Jan 27 '19 at 08:07
  • this give me the error in developer console Uncaught SyntaxError: Unexpected end of input – Salik Salman Jan 27 '19 at 08:09
  • Post your JQuery code please – Batsheva Hansav Jan 27 '19 at 20:24

0 Answers0