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
Share on other sites

This thread is more than a year old. Please don't revive it unless you have something important to add.

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.

Guest
Reply to this topic...

×   Pasted as rich text.   Restore formatting

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

×
×
  • 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.