Jump to content

query within class failing


doddsey_65

Recommended Posts

i have a simple class which sees if there are any members in the database with the supplied details, then returns a simple number to show how many results there are, but it isnt working and throwing the error:

 

Warning: mysql_num_rows() expects parameter 1 to be resource, boolean given in C:\wamp\www\classTest\classes\user_process.php on line 52

 

here is the class:

 

require_once("db_mysql.php");
require_once("./init.php");

class emptyArgs extends Exception 
{ 
function __toString()
{
	return "<strong>Empty Arguments</strong>";
}
}

class user_process
{
public $user_name;
public $password;

public function login($user_name, $password)
{
	try
	{
		if (empty($user_name) || empty($password))
		{
			throw new emptyArgs();
		}

		if ($user_name == "")
		{
			throw new emptyArgs();
		}

	}
	catch (emptyArgs $e)
	{
		echo $e;
		echo "<p>Please Supply All Details Marked *</p>";
	}

	echo $user_name;
	echo $password;

	$query = <<<QUERY
				SELECT COUNT(*) 
				FROM ".TBL_PREFIX."members
				WHERE user_username = '$user_name'
				AND user_password = '$password'
QUERY;
	$process = mysql_query($query);
	$result = mysql_num_rows($process); // Line 52 where the error originates

	return $result;
}
}

 

and here is the call:

 

$user = new user_process();
$user->login("username", "password");

 

All of the database details are correct and the values do match in the database. Where am i going wrong?

 

Note that this class is just for testing and not actually used.

Link to comment
https://forums.phpfreaks.com/topic/221950-query-within-class-failing/
Share on other sites

Archived

This topic is now archived and is closed to further replies.

×
×
  • Create New...

Important Information

We have placed cookies on your device to help make this website better. You can adjust your cookie settings, otherwise we'll assume you're okay to continue.