Reputation: 187
I know that we already have thousands of this question in the site. Trust me I looked upon them.
So, my problem is that, by reasons unknow my SQL query keeps returning false, and because of that, my mysqli_fetch_assoc()
keeps failing. But, this query was transcribed in to my phpmyadmin, and I know that works because it works there.
Here is the php code:
<?php
require('connect.php');
$login = $_POST['login'];
$pass = $_POST['pass'];
mysqli_select_db($conn, "cerberusdb");
$sql = "SELECT _login, _pass FROM 'tblogin' WHERE _login ='".$login."' AND _pass = '".$pass."'";
$result = mysqli_query($conn, $sql);
if(mysqli_fetch_assoc($result) > 0){
$return = 'true';
$echo $return;
}else{
$return = 'false';
echo $return;
}
mysqli_close($conn);
?>
And this is the Javascript that handles the request, by the way, I know that works to, already tested the $.post()
to know for sure if the vLogin and vPass it's been passed to the php.
$(document).ready(function(){
$("#logForm").submit(function(e) {
e.preventDefault();
var vLogin = $("#lgInput").val(), vPass = $("#lgPass").val();
$.post('login.php', {login: vLogin, pass: vPass}, function(data, textStatus, xhr){
alert('data:'+data+'\nstatus: '+textStatus);
});
});
});
So, if anybody can helps I'll be appreciated. Thanks in advance.
P.s.: I've looked upon the PHP documentation and finded thar mysqli_query()
when the query is a SELECT
returns an object, and when fails returns false. I just can't understand why it's failing.
Upvotes: 1
Views: 75
Reputation: 10548
Single Quotes
(') are not allowed using table name or column name. Use backtick
(`)
Change
'tblogin'
To
`tblogin`
Like
$sql = "SELECT _login, _pass FROM `tblogin` WHERE _login ='".$login."' AND _pass = '".$pass."'";
$result = mysqli_query($conn, $sql);
[NOTE: Click when to use single quotes double quotes and backticks to know more
Upvotes: 1