Hello again. This code is returning the result of 1 when it should be returning 0 as there are no records in the table of my database. If you can point out my error I would appreciate it.
PHP Code:
//get the username
$username = mysql_real_escape_string($_POST['user_name']);
//mysql query to select field username if it's equal to the username that we check '
$result = mysql_query('SELECT user_name FROM ajax_users WHERE user_name = "'. $username .'"');
echo $username;
//if number of rows fields is bigger them 0 that means it's NOT available '
if(mysql_num_rows($result)>0){
//and we send 0 to the ajax request
echo 0;
}else{
//else if it's not bigger then 0, then it's available '
//and we send 1 to the ajax request
echo 1;
}
There is no data in the table. I have added records and tested adding them via another form and that all works fine. But now there are no records in the table. We can discount that.
Thanks
SELECT user_name FROM ajax_users WHERE user_name LIKE
Warning: mysql_num_rows() expects parameter 1 to be resource, boolean given in C:\\wamp\\www\ echterms5\\index.php on line 26
It’s blank after LIKE as if $username isn’t getting populated with a value from the form and then the num_rows() error I don’t know about.
Maybe the form isn’t passing the value?
after the $username = mysql_real_escape_string($_POST[‘user_name’]);
and see what is returned to the screen that will give you a basis of what the query is using then try echoing out the sql like this
$sql = “SELECT user_name FROM ajax_users WHERE user_name LIKE ‘$username’”;
echo $sql;
exit;
$result = mysql_query($sql);
$username = @mysql_real_escape_string($_POST['user_name']);
$sql = 'SELECT user_name FROM ajax_users WHERE user_name LIKE "'. $username .'"';
$result = mysql_query($sql);
//mysql query to select field username if it's equal to the username that we check
echo $username;
as you put up along with my capture of $username then it returns
1
I can put whatever code you want up. What would you like the javascript file? I posted the php and the form alread.