I allways seem to have errors when working with mySQL num rows for some reason.
Basicly im writing a function so that I can type datacheck (tablecheck, fieldcheck, datacheck); and using that I will be able to use that to see if there is a record in table check where fieldcheck=datacheck.
So im using this code:
function datacheck ($tablecheck, $fieldcheck, $datacheck) {
if(mysql_num_rows('mysql_query("SELECT $fieldcheck FROM $tablecheck WHERE $fieldcheck = \'$datacheck\'"); ') < 1){ return true; }else { return false; }
}
Then im validating my form by using
if (empty($username)) { $error.="You must supply a username!<br>";}
elseif (datacheck (members, username, $username)) { $error.="Sorry the username you have chosen is allready in use or is awaiting activation!<br>";};
To call the function and check if the username is allready in my table.
However I get this error
Warning: mysql_num_rows(): supplied argument is not a valid MySQL result resource in E:\My Documents\www\index.php on line 26
Line 26 is my function the specific code it suggests is
if(mysql_num_rows('mysql_query("SELECT $fieldcheck FROM $tablecheck WHERE $fieldcheck = \'$datacheck\'"); ') < 1){ return true; }else { return false; }
Any advice apriciated
Cheers, Jamie.