Hello please I don't know what I am doing wrong here. I am trying to use ajax for a login page. The ajax is working but the successful response is not from the file I specified. I need it to read response from the login_validate.php but I am getting response from the dbconnect.php which shouldn't work like that.
this is the index.php which is the ajax page
jQuery(document).ready(function(){
jQuery(".login").submit(function(e){
e.preventDefault();
var formData = jQuery(this).serialize();
$.ajax({
type:"POST",
url:"login_validate.php",
data:formData,
success: function(response){
/** alert (response);
}, error: function(jqXHR, textStatus, errorThrown){
alert('error');
} **/
if(response == "True")
{
//alert('Yes');
//$.jGrowl("Loading File Please Wait......", { sticky: true });
$.jGrowl("Welcome... Redirecting", { header: 'Login Successful' });
var delay = 3000;
setTimeout((function(){ window.location = 'welcome.php' }), delay);
}else{
//alert('No');
$.jGrowl("Invalid Login Details", { header: 'Access Denied' });
}
}
});
return false;
});
});
this is the dbconnect.php
<?php
// connect to database
$hostname = "localhost";
$username = "root";
$password = "";
$dbname = "cbt2";
$conn = new mysqli($hostname, $username, $password, $dbname);
// check connection
if ($conn->connect_error) {
die ('Error connecting to database' . $conn->connect_error);
} else {
echo "Connection Successful";
}
?>
this is the login_validate.php
<?php
require 'admin/dbconnect.php';
require 'admin/core.php';
if(loggedin())
{
header('location:welcome.php');
}
if (isset($_POST['loginbtn'])){
$name=$_POST['username'];
$pass= $_POST['password'];
$qry="SELECT * FROM student WHERE username='$name' AND password='$pass' LIMIT 1";
$qrycheck=$conn->query($qry);
if ($qrycheck->num_rows > 0){
while($fetch = $qrycheck->fetch_assoc()){
$class=$fetch['class'];
$fullname=$fetch['fullname'];
$username=$fetch['username'];
$dept=$fetch['dept'];
$id=$fetch['id'];
$_SESSION['stdid']=$id;
$_SESSION['user']=$username;
$_SESSION['name']=$fullname;
$_SESSION['class']=$class;
$_SESSION['dept']=$dept;
}
echo "True";
} else {
echo "False";
}
}
?>
So the successful response I am getting is the echo 'Connection Successful'
and it should be echo 'True'