Alright so I have 2 folders. This is how my layout looks on my server right now.
folders:
Ajax/
Processor/
Files:
Login.php
Carelogin.php
Originally I did NOT have a processor folder. So I had my login.php file right under my carelogin.php and everything worked just fine.
Now since I put my login.php file into the processor folder and changed the path in my functions.js in my ajax folder everything is all messed up.
This is my ajax functions.
$(function() {
$("#submit_login").click(function() {
var username = $("input#username").val();
if (username == "") {
$('.errormess').html('Please Insert Your Username');
return false;
}
var password = $("input#password").val();
if (password == "") {
$('.errormess').html('Please Insert Your Password');
return false;
}
var dataString = 'username='+ username + '&password=' + password;
$.ajax({
type: "POST",
url: '/processor/login.php',
data: dataString,
dataType: "html",
success: function(data) {
if (data == 0) {
$('.errormess').html('Invalid username/password combination');
} else {
$('.errormess').html('<b style="color:green;">Thanks for loggin in</b>');
document.location.href = 'home.php';
}
}
});
return false;
});
});
As you can see I have it pointed to the /processor/login.php and it is not working anymore. Just keeps logging me in like its not even checking the login.php file anymore. Even with the wrong creds I can still log in now.
When I had that url just pointed to login.php it all worked perfect.
this is my carelogin.php
<!DOCTYPE html>
<html>
<head>
<meta charset="UTF-8"/>
<meta name="viewport" content="width=device-width, initial-scale=1.0">
<link type="text/css" rel="stylesheet" href="css/pagecss/logincss.css" />
<script type="text/javascript" src="ajax/jquery.js"></script>
<script type="text/javascript" src="ajax/functions.js"></script>
</head>
<body>
<div class='container'>
<img src='images/tigger.png' class='logo'/>
<div class="login_form">
<form method="POST" action="/processor/login.php">
<input type="text" name="username" id="username" placeholder="Username" /><br />
<input type="password" name="password" id="password" placeholder="Password" /><br />
<input type="submit" id="submit_login" name="submit" class="inputbutton grey" value="Login" />
<span class="login_loading"></span>
<span class="errormess"></span>
</form>
<p class='version'>Version 1.6.1119.15 </p>
</div>
</div>
</body>
</html>
finally, here is my login.php file
<?php
session_start();
require 'connect.php';
if(mysqli_connect_errno()) {
echo 'Failed to Connect to MySQL' . mysqli_connect_errno();
}
if (isset($_POST)) {
$user = $_POST['username'];
$pass = md5($_POST['password']);
$query = mysqli_query($conns, "SELECT * FROM tech WHERE username = '$user' and password = '$pass'") or die("Can not query the DB");
$count = mysqli_num_rows($query);
if($count == 1) {
$_SESSION['username'] = $user;
echo $user;
}
}
?>
I see in your folder list:
'Processor'
while in your ajax call your url points to:
'/processor/login.php'
Keep in mind that PHP is case sensitive
If your ajax cal is in the 'Ajax folder' you maybe need to do:
'../processor/login.php'
add:
else{
echo $count;
}
after:
if($count == 1) {
$_SESSION['username'] = $user;
echo $user;
}
your ajax condition will always execute the else statement because the value that returns to your ajax is the user's username.
also edit this:
<script type="text/javascript" src="ajax/jquery.js"></script>
<script type="text/javascript" src="ajax/functions.js"></script>
to this:
<script type="text/javascript" src="../ajax/jquery.js"></script>
<script type="text/javascript" src="../ajax/functions.js"></script>