I am using PHP + jQuery AJAX to log a user into my site. The PHP connects to the database and the jquery connects to the PHP file and everything works until it comes time to actually log in. When I type in my username and password, the file returns an error. I had this working about a week ago but I was doing some code cleanup and I accidentally deleted the script where it performed the log in and now I can’t get it to work. Here is my PHP file:
<?php
include('.conf.php');
$user = $_POST['user'];
$pass = $_POST['pass'];
$result = mysql_query("SELECT * FROM accountController WHERE username = '$user'");while ($row = mysql_fetch_array($result)) {
if (sha1($user.$pass) == $row['pword']) {
setcookie('temp', $row['username']);
session_start();
$_SESSION['login'] = 1;
$_SESSION['uname'] = $row['username'];
echo "success";
}
}
?>
I do believe the PHP file is echoing the correct statement and yes, the passwords in the database are sha1 encrypted. Here is the jquery code:
$('.mainlogin').submit(function() {
$.ajax({
url: 'log.php',
type: 'POST',
data: {
user: username,
pass: password
},
success: function(response) {
if(response == 'success') {
window.location.reload();
} else {
$('.logerror').fadeIn(250);
}
}
});
return false;
});
Thanks for all the help!
EDIT: I am not sure what is wrong right now but it won’t log me in no matter what I try. I have corrected everything you guys suggested below, but to no avail. Anything wrong in my PHP file possibly?
try this:
or chaneg data params
AND USE &!!!!