Jump to content

Why am I getting no response from my loginizer.php file?


Go to solution Solved by maxxd,

Recommended Posts

I am making a simple login with jQuery ajax but I have a little problem. I get no response from my loginizer.php . 

My login page (index.php) contains the following code.

 

<form action="loginizer.php"  onsubmit="return submitForm();"  method="post" class="box">

<div id="error" ></div>

 <input id="matNo" name="matNo" class="input is-link is-rounded" type="text" placeholder="e.g. 2015/1/55852EE">
   <input id="password" name="password" class="input is-link is-rounded" type="password" placeholder="********">

 <button type="submit"  id="submit" name="submit" class="button is-link is-small">Login</button></form>

 

 

My loginizer php contains the code:

 

<?php
if(isset($_POST['submit'])){
require("db.php");
$table="Students";
$pUser=$_POST['matNo'];
$pPass=$_POST['password'];


$sql= $conn->prepare("SELECT * FROM  $table WHERE Email=?");
$sql->bind_param("s",$pUser);
$sql->execute();
$result = $sql->get_result();
$row = $result->fetch_assoc();
$user= $row['Email'];
$pass = $row['Password'];
$errMsg="Invalid Credentials";
$errMsg1="username doesn't exist";
$successMsg = "successLogin";
if($result->num_rows < 1)
{

echo json_encode($errMsg1);
exit;
}
elseif($pUser == $user && $pPass !== $pass)
{
echo json_encode($errMsg);
exit;
}
else{
echo json_encode($successMsg);
exit;
}
}
?>

 

Ans lastly myJquery.js file which contains:

 

 

function submitForm()
{

 var userid=$("#matNo").val();
 var pass=$("#password").val();
 if(userid!="" && pass!="")
 {

  $("#submit").html("Please Wait...");
  $.ajax
  ({
  type:'post',
  url:'loginizer.php',
  data:{
   matNo:userid,
   password:pass
  },
   dataType:'json',

  success:function(response) {

  if(response=="successLogin")
  {

    window.location.href="dash/home/";
  }
  else
  {

    $("#error").html(response);
    //alert("Wrong Details");
  }
 }

   });
 }

 else
 {
  alert("All details are required");
 }

 return false;
}

 

 

The issue is that I get blank response . If I also change the url in the jQuery/Ajax code to index.php, it comes back with a response consisting of the html of the index.php. If I remove the dataType: 'json', it's still no response.

 

Thanks for your help in advance!!!

Additionally, if the only thing your javascript is going to do is either redirect or show an error, then there's really no reason to use javascript / ajax at all.  Just use a normal form process and keep it simple.

 

  • Thanks 1
This thread is more than a year old. Please don't revive it unless you have something important to add.

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.

Guest
Reply to this topic...

×   Pasted as rich text.   Restore formatting

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

×
×
  • Create New...

Important Information

We have placed cookies on your device to help make this website better. You can adjust your cookie settings, otherwise we'll assume you're okay to continue.