If (html == true) not satisfying this condition

after checking the email and password from the table, let's say it goes into studentDashBoard.php file. but every time i get false and its error gives wrong id or psd.

Here is my html markup:

login.php

:

<form action="login.php" id="LoginForm" name="LoginForm" method="post" onsubmit=" return validate();">
                <div class="form-group">
                   <label for="exampleInputEmail1">Email address</label>
                   <div class="input-group">
                   <span class="input-group-addon" id="basic-addon1"><span class="glyphicon glyphicon-user"></span></span>
                     <input type="email" name="email" class="form-control" id="exampleInputEmail1" placeholder="Enter email" required>
                   </div>
                   <p id="statusEmail"></p>

                </div>
                <div class="form-group">
                    <label for="exampleInputPassword1">Password</label>
                     <div class="input-group">
                   <span class="input-group-addon" id="basic-addon1"><span class="glyphicon glyphicon-star"></span></span>
                     <input type="password" name="password"class="form-control" id="exampleInputPassword1" placeholder="Password" required>
                   </div>
                    <p id="statusPsd"></p>

                 </div>
                 <hr/>

                  <p id="status"></p>
                 <button type="button" class="btn btn-success"><span class="glyphicon glyphicon-arrow-left">Back</button>
                 <button type="submit" name="submit" id="loginButton" class="btn btn-primary"><span class="glyphicon glyphicon-lock">Login</button>
                 <p><br/></p>
                 <p id="notice"> If not registered yet</p><br/>
          <button type="button" id="SignUp" class="btn btn-danger">SingUp</button>

</form>

      

Here is the jQuery code:

$(document).ready(function(){

    $("#loginButton").click(function(e){
      email=$("#exampleInputEmail1").val();
       e.preventDefault();
      password=$("#exampleInputPassword1").val();
      $.ajax({
           type: "POST",
            url: "StudentLogin.php",
            data: "email="+email+"&password="+password,

            success:function(html)  
            {
              if(html==true){
               ---> this function is not working while I am login with correct data
                window.location="studentDashBoard.php";
               }
               else{
                $("#status").html("<p>worng id or psd</p>");
               }
            }
       });
    });
});

      

and StudentLogin.php

code

<?php
$link = mysqli_connect('localhost','root','','users'); 
if (!$link) { 
    die('Could not connect to MySQL: ' . mysqli_error($link)); 
} 

if(isset($_POST['submit']))
{
  echo "submit";
  $email=$_POST['email'];

  $password=$_POST['password'];

  $sql = "SELECT * FROM student WHERE email='$email' AND password='$password' ";

  $query = mysqli_query($link,$sql);

  $result= mysqli_num_rows($query);

  if($result > 0)
  {
       echo 'true';
  }
  else
  {
      echo 'false';
  }
}

  mysqli_close($link);  
?>

      

studentDashBoard.php

The file just prints "hello" nothing else.

If you need more information, let me know

+3


source to share


3 answers


Instead of:    if(isset($_POST['submit'])){ }

 in the file, studentLogin.php

I changed to



if( isset($_POST['email']) && isset($_POST['password']) ) {

and now it works

+1


source


Try using condition if

like below:



if(html=="true")

{}

0


source


Replace

success:function(html)  
        {
           if(html==true)
           {

           }
         }

      

with something like

success:function(html)  
        {
          if($('#result').html(html)==true)
           {

           {
        }

      

0


source







All Articles