SQL Errors
#10

Here's more code that could be useful:

Code:
MySQLNewColumns() //initializes new rows to the current table!
{
	new haystack[64];
	format(haystack,sizeof(haystack),"SHOW columns FROM `users`");
	samp_mysql_query(haystack);
 	samp_mysql_store_result();
	if(samp_mysql_num_rows() < 10)
	{
		samp_mysql_query("ALTER TABLE `users` ADD Admin INT(10) NOT NULL DEFAULT '0'");
		samp_mysql_query("ALTER TABLE `users` ADD Donator INT(10) NOT NULL DEFULT '0'");
		samp_mysql_query("ALTER TABLE `users` ADD cmem INT(10) NOT NULL DEFULT '0'");
		samp_mysql_query("CREATE TABLE IF NOT EXISTS `banlist`(`id` INT(11) NOT NULL auto_increment PRIMARY KEY,\
		`Name` VARCHAR(30) NOT NULL,\
		`IP` VARCHAR(40) NOT NULL,\
		`Reason` TINYTEXT NOT NULL)");
	}
	return 1;
}
You mean this?

The registering and shit work, and my password saves properly, but money, kills, deaths, admin level, donator level, and clan membership will not save.


Code:
stock RegPlayer(playerid,pass[])
{
  MySQLCheck();
  new pName[MAX_PLAYER_NAME],
		query[256],
		string[256];
		
	GetPlayerName(playerid,pName,sizeof(pName));
	samp_mysql_real_escape_string(pName,pName);
	samp_mysql_real_escape_string(pass,pass);
	format(query,sizeof(query),"INSERT INTO `users` (Username,Password) VALUES ('%s',md5('%s'))",pName,pass);
	samp_mysql_query(query);
	samp_mysql_free_result();

	format(string,sizeof(string),">> Account %s successfully registered ( Password: %s )",pName,pass);
	SendClientMessage(playerid,GREY,string);
	SendClientMessage(playerid,GREY,"You have been automatically logged in");
	LoggedIn[playerid] = 1;
	AccRegistered[playerid] = 1;
	AccountInfo[playerid][Money] = 0;
	AccountInfo[playerid][Kills] = 0;
	AccountInfo[playerid][Deaths] = 0;
	AccountInfo[playerid][AdminLevel] = 0;
	AccountInfo[playerid][DonatorLevel] = 0;
	AccountInfo[playerid][ClanMember] = 0;
	return 1;
}

stock LoginPlayer(playerid,pass[])
{
  new pName[MAX_PLAYER_NAME],
		query[256],
		string[256],
		result[256],
		loop[256],
		poop = 1;

	GetPlayerName(playerid,pName,sizeof(pName));
	MySQLCheck();
	samp_mysql_real_escape_string(pName,pName);
	samp_mysql_real_escape_string(pass,pass);
	format(query,sizeof(query),"SELECT * FROM `users` WHERE Username = '%s' AND Password = md5('%s')",pName,pass);
	samp_mysql_query(query);
	samp_mysql_store_result();
	samp_mysql_fetch_row(result);
	
	if(samp_mysql_num_rows() == 1)
	{
	  samp_mysql_strtok(loop, "|", result);
	  while(samp_mysql_strtok(loop, "|", ""))
		{
		  if(poop == 3) AccountInfo[playerid][Money] = strval(loop);
		  if(poop == 4) AccountInfo[playerid][Kills] = strval(loop);
		  if(poop == 5) AccountInfo[playerid][Deaths] = strval(loop);
		  if(poop == 6) AccountInfo[playerid][AdminLevel] = strval(loop);
  		  if(poop == 7) AccountInfo[playerid][DonatorLevel] = strval(loop);
  		  if(poop == 8) AccountInfo[playerid][ClanMember] = strval(loop);
		  poop++;
		}
		samp_mysql_free_result();

		GivePlayerMoney(playerid,AccountInfo[playerid][Money]);
		LoggedIn[playerid] = 1;
		format(string,sizeof(string),">> You have been successfully logged in. (Kills/Score: %d | Deaths: %d | Money: %d | Donator Level %d)",AccountInfo[playerid][Kills],AccountInfo[playerid][Deaths],AccountInfo[playerid][Money],AccountInfo[playerid][DonatorLevel]);
		SendClientMessage(playerid,GREY,string);
		if(AccountInfo[playerid][AdminLevel] > 0)
		{
		  new send[128];
		  format(send,sizeof(send),">> %s has logged in as level %d Admin",pName,AccountInfo[playerid][AdminLevel]);
		  SendClientMessageToAll(YELLOW,send);
		}
		printf("User %s has logged in ( Money: %d,Kills/Score: %d,Deaths: %d, Donator level: %d )",pName,AccountInfo[playerid][Money],AccountInfo[playerid][Kills],AccountInfo[playerid][Deaths],AccountInfo[playerid][DonatorLevel]);
		return 1;
	}
	else
	{
	  SendClientMessage(playerid,RED,">> Wrong Password");
	  Wrongattempt[playerid] += 1;
	  printf("Bad log in attempt by %s (Total attempts: %d)",pName,Wrongattempt[playerid]);
	}
	return 1;
}
Reply


Messages In This Thread
SQL Errors - by Burridge - 29.06.2009, 00:38
Re: SQL Errors - by Burridge - 29.06.2009, 07:51
Re: SQL Errors - by MenaceX^ - 29.06.2009, 08:44
Re: SQL Errors - by ledzep - 29.06.2009, 08:55
Re: SQL Errors - by Ignas1337 - 29.06.2009, 08:56
Re: SQL Errors - by Ignas1337 - 29.06.2009, 08:56
Re: SQL Errors - by Burridge - 29.06.2009, 09:04
Re: SQL Errors - by ledzep - 29.06.2009, 09:11
Re: SQL Errors - by Burridge - 29.06.2009, 09:13
Re: SQL Errors - by Burridge - 29.06.2009, 09:25

Forum Jump:


Users browsing this thread: 2 Guest(s)