mysql_num_rows error??!

houssam_ballout

New Member
Hello all,
when I try to run the code below , the following error is generated:
Warning: mysql_num_rows(): supplied argument is not a valid MySQL result resource in c:\wamp\www\mini\check.php on line 18

what is that problem?
thanks...

PHP:
<?php
require('connect.php');

if(isset($_POST['check']))
{
$username = $_POST['username'];
}
$query = "select username from users where username = " . $username;
$result = mysql_query($query);
$num = mysql_num_rows($result);
mysql_close();

if ($num == 0 )
{
echo "Username available";
}

else
{
echo "not";

}

?>
 
Usually when this happens if you put an "echo mysql_error();" in there after your select query you know what's wrong.

Try changing your query string to $query = "select username from users where username = \"$username\"";
 
Back
Top