MySQL connection problem.
#8

Code:
public OnPlayerConnect(playerid)
{
	new string[164];
	new Query[256];
	GetPlayerName(playerid,PlayerInfo[playerid][Username],24);
	mysql_format(mysql, Query, Query,"SELECT `Username` FROM `Users` WHERE `Username` = %s", PlayerInfo[playerid][Username]);
	mysql_store_result();
	if(mysql_num_rows() != 0)//if number of rows is different from 0 then continue
	{
	format(string,sizeof(string),"Hey, %s! \nYour account is registered.\nPlease enter the password to log in!",PlayerInfo[playerid][Username]);
	ShowPlayerDialog(playerid,0,DIALOG_STYLE_INPUT,"Log in",string,"Login","");
	}
	else
	{
	format(string,sizeof(string),"Hey, %s! \nYour account is not registered. \nPlease register to continue!",PlayerInfo[playerid][Username]);
	ShowPlayerDialog(playerid,1,DIALOG_STYLE_INPUT,"Register",string,"Register","");
	}
	mysql_free_result();
	GivePlayerMoney(playerid, 5000);
	return 1;
}
Code:
public OnDialogResponse(playerid, dialogid, response, listitem, inputtext[]) {
    if(dialogid == 0) {
		if(strlen(inputtext) == 0) {
			return 1;
		} else {
		LoginPlayer(playerid,inputtext);
		}
	}
    if(dialogid == 1) {
		if(strlen(inputtext) == 0)	{
		ShowPlayerDialog(playerid,1,DIALOG_STYLE_INPUT,"Register - Enter your password","You are about to register a new account! \nPlease choose the password for it! \n","Register!","");
		} else {
		new EscapedText[60];
		new Query[256];
		new connhandle = playerConnectHandle[playerid];
 		if(connhandle == -1) {
  			connhandle = g_mysql_handle;
 		}
		mysql_real_escape_string(inputtext, EscapedText);
		format(Query, sizeof(Query), "INSERT INTO `Users` (Username,Password,Money) VALUES ('%s','%s,'0')",PlayerInfo[playerid][Username],EscapedText);
		
        mysql_function_query(connhandle, Query, true, "", "d",playerid);
		SendClientMessage(playerid,green,"You have been successfully registered!");
		GivePlayerMoney(playerid,5000);
		SetPlayerScore(playerid,100);
		}
	}
	return 1;
}
^^First one is login second dialog is register.

Code:
stock LoginPlayer(playerid,const password[]) {
	new EscapedText[60];
	new Query[256];
	mysql_real_escape_string(password, EscapedText);
	mysql_format(mysql, Query, Query,"SELECT * FROM `Users` WHERE `Username` = '%s' AND `Password` = '%s'",PlayerInfo[playerid][Username],EscapedText);
	mysql_store_result();
	if(mysql_num_rows() != 0) {
		SendClientMessage(playerid,green,"You have been logged in!");
		LoadStats(playerid);
	} else {
		SendClientMessage(playerid,red,"Wrong password!");
		Kick(playerid);
	}
	mysql_free_result();
	return 1;
}

stock LoadStats(playerid) {
	new Query[256];
	mysql_format(mysql, Query, Query,"SELECT * FROM `Users` WHERE `Username` = '%s' ", PlayerInfo[playerid][Username]);
	mysql_store_result();
	mysql_fetch_row_format(Query, "|");
	sscanf(Query, "e<p<|>s[24]s[23]i>", PlayerInfo[playerid]);
	mysql_free_result();
	GivePlayerMoney(playerid,PlayerInfo[playerid][Money]);
	return 1;
}
*** Just to add I grabbed this code from the internet... YES. I am trying to learn mysql, at first I noticed that the code was fucked up, but I edited it. so yeah there could be something wrong, But no errors or warnings when compiled. ***
Reply


Messages In This Thread
MySQL connection problem. - by Glenn332 - 29.01.2015, 16:59
Re: MySQL connection problem. - by PowerPC603 - 29.01.2015, 17:39
Re: MySQL connection problem. - by Glenn332 - 29.01.2015, 17:42
Re: MySQL connection problem. - by PowerPC603 - 29.01.2015, 17:47
Re: MySQL connection problem. - by Glenn332 - 29.01.2015, 17:54
Re: MySQL connection problem. - by Smally - 29.01.2015, 17:58
Re: MySQL connection problem. - by PowerPC603 - 29.01.2015, 18:00
Re: MySQL connection problem. - by Glenn332 - 29.01.2015, 18:02
Re: MySQL connection problem. - by PowerPC603 - 29.01.2015, 18:08
Re: MySQL connection problem. - by Glenn332 - 29.01.2015, 18:11

Forum Jump:


Users browsing this thread: 2 Guest(s)