Sign in to follow this  
NightMarez

Problem getting data from mysql (rows)

Recommended Posts

Hi all, im having a problem with this code (descriped below)
int checklogin(char * username, char * password)
{
	mysql_query(pConn,"SELECT * FROM account");
	result = mysql_use_result(pConn);
	mysql_free_result(result);

	char* query = new char[100];
	sprintf(query,"SELECT * FROM account WHERE username=%s && password=%s", username, password);
	
	if(!mysql_query(pConn,query))
	{
		// error doing the query
		Log2File(TRUE, "(MySQL) ERROR : %s\n", mysql_error(pConn));
		return 0;
	}
	else
	{
		result = mysql_use_result(pConn);
		// fetch all the rows from the query.
		while ((row = mysql_fetch_row(result))) 
		{ 
		}

		// if there is no rows returned.
		if(mysql_num_rows(result) == 0)
		{
			mysql_free_result(result);
			return 0;
		}

		// the username and password match.
		else
		{
			mysql_free_result(result);
			return 1;
		}
	}
	return 0;
}

it is supposed to check the category account for a match with the descriped username/password, but it doesnt, it crashes my application and i cant seem to find the error. i do however belive it got something to do with fecthing of the row... btw, im making this in visual c++ 6 (sp5) as a win32 app anyone got an idea where this error is happening ?

Share this post


Link to post
Share on other sites

Create an account or sign in to comment

You need to be a member in order to leave a comment

Create an account

Sign up for a new account in our community. It's easy!

Register a new account

Sign in

Already have an account? Sign in here.

Sign In Now

Sign in to follow this