Hi all. I\'m having a problem returning a mysql result set from a function I wrote and I\'m hoping someone will be able to help.
I have a function called db_query that accepts one parameter, $querystring.
This is the function:
function db_query($querystring)
{
global $sess_allow;
global $sess_clearance;
if (!isset($sess_allow) || !isset($sess_clearance) || $sess_allow != \"yes\" || $sess_clearance != \"1\")
{
die(\"get outta here.\");
}
else
{
$query = mysql_db_query(\"designincognito_dev\",\"$querystring\")
or die(\"invalid query\");
if ($query)
{
return $query;
header(\"location:index.php\");
}
else
{
die(\"invalid query\");
}
}
}
Now, the problem is that after I call the function, db_query($querystring), with the appropriate value subbed in of course, when I try to access $query, which should theoretically be returned by the function and contain the mysql result set from the function, I get the following error:
Warning: Supplied argument is not a valid MySQL result resource in c:\phpdev\www\designincognito\admin\manage_users.action.php on line 18
Can anybody tell me why this is happening?
If I change the lines of the funtion:
return $query;
header(\"location:index.php\");
to:
echo mysql_num_rows($query);
die()
the number of rows in the result set gets output to the browser. However if I attempt to return $query and echo mysql_num_rows($query) in the page calling the function, I get the error message above.
If anyone could pass along a solution to this it would be greatly appreciated.
Thanks in advance,
Pablo