PDA

View Full Version : Resolved mysql_num_rows error



Dubz
Oct 9th, 2011, 05:48 PM
I'm getting this error but I don't see what I did wrong :confused:

Error:

Warning: mysql_num_rows(): supplied argument is not a valid MySQL result resource in *** on line 29
Unknown column 'Dubz' in 'where clause'

Code:


function newuser($username, $password){
global $user;
$passed = true;
if(!$username){
echo 'You must enter a username!</br>';
$passed = false;
}
if(!$password){
echo 'You must enter a password!</br>';
$passed = false;
}
elseif($user['rank']<$ranks['mod']){
echo 'You are not allowed to register users!</br>';
$passed = false;
}
elseif($passed==true){
$users2 = mysql_query("SELECT * FROM Users WHERE user=".$username);
$count = mysql_num_rows($users2) or die (mysql_error()); //ERROR LINE
if($count!=0){
echo 'Username already registered!';
}
}
}

Dubz
Oct 9th, 2011, 05:58 PM
Fixed

Changed this

$users2 = mysql_query("SELECT * FROM Users WHERE user=".$username);

To this

$users2 = mysql_query("SELECT * FROM Users WHERE user='$username'");