I have recently created a if statement checking to see if a username exists on the database, but for some reason it doesn't work I create a function which run my sql queries
function makeQuery($query)
{
//build select query
$msg="";
//connect to mysql
if(!($con1 = mysql_connect("localhost","myname","password")))
{
$msg.="could not connect to database<br/>";
}
if(!mysql_select_db("mdb_dd615",$con1))
{
$msg.="could not open database<br/>";
}
if(!($result = mysql_query($query,$con1)))
{
$msg.="could not execute query:".mysql_error()."<br/>";
}
mysql_close($con1);
return true;
}
and when I try to use the query to run the mysql_num_rows
$checkusername = "select * from tutordetails where username = '".mysql_escape_string($_POST['username'])."'";
$result=makeQuery($checkusername);
if(mysql_num_rows($result)==1)
{
$errormsg.="<h3>Sorry this username is already in use</h3><br/>";
}
I get the following error on my page
Warning: mysql_num_rows(): supplied argument is not a valid MySQL result resource in ./RegisterPage.php on line 76
which is referring to the line running the mysql_num_rows, when I do all the sql code within the page it works, and also when i use the function created to save information it works fine. Am totally confused any help would be much appreciated
🙂