I have a code here that will check if a username is available but I am getting a error message stating this:
<br /> <b>Warning</b>: mysql_result() expects parameter 1 to be resource, boolean given in <b>C:\xampp\htdocs\username_check.php</b> on line <b>8</b><br /> $username_result
I searched stackoverflow and found a few similar questions but none of them help.
my first php code is this:
<?php
mysql_connect('localhost','username','password');
mysql_select_db('logins');
?>
my second php code is this:
require 'db_connect.php';
if (isset($_POST['username'])) {
$username = mysql_real_escape_string($_POST['username']);
if (!empty($username)) {
$username_query = mysql_query ("SELECT COUNT('id') FROM 'users' WHERE 'username'='$username'");
$username_result = mysql_result($username_query, 0);
}
}
?>
and my jquery is this:
jQuery( '#box1' ).keyup(function(){
var username = jQuery(this).val();
jQuery( '#msg_out1' ).html('<img src="/img/ajax-loader.gif" width="43" height="11" /> Checking availability... ');
if (username != '') {
jQuery.post('/click/username_check.php', { username: username }, function(data){
jQuery( '#msg_out1').text(data);
});
}else {
jQuery( '#msg_out1' ).html('Choose a Username.').css('color','grey').css('font- size','15px').css('margin-left','40px');
}
});
});
I use jQuery instead of $ because i specified at the top before document ready a jQuery no conflict code.