MySQL help
#1

Well, I got problem saving nickname in database for some reason

pawn Код:
new query[200], IP[16];
    GetPlayerIp(playerid, IP, 16);
    format(query, sizeof(query), "INSERT INTO accounts (UserName, Password,kills, deaths, Rank, Level, Operator, TagAllowed, dRank, Score, PrestigeWeaponID1,PrestigeWeaponID2,PrestigeWeaponID3,PrestigeWeaponID4) VALUES('%s', SHA1('%s'), 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0 ,0)", PlayerName2(playerid), passwordstring);
    mysql_query(query);
    format(query, sizeof(query), "INSERT INTO accounts (CapturedZones,PistolSkills,SicPistolSkill,DeserteagleSkill,Shotgun,CombatShotgun,UziTec,Mp5,ak47,m4,Sniper,LastPromotionsDay,LastPromotionsMonth,LastPromotionsYear) VALUES(0, 0, 0, 0, 0,0,0,0,0,0,0,0,0,0,0,0)");
    mysql_query(query);
    format(query, sizeof(query), "INSERT INTO accounts (HiredDay, HiredMonth, HiredYear, CM, SiM, Money, IP) VALUES(0, 0, 0, 0, 0, 0,'%s')",IP);
    mysql_query(query);
    //We do not need to store or free a result as it
    //is not a select statement. We can now send the
    //client a registration success message and set the
    //Login variable to 1.
    SendClientMessage(playerid, -1, "You have been registered on this server!");
    PlayerInfo[playerid][LoggedIn] = 1;
everythings saved.
but nickname not.
NOTE: UserName = VARCHAR(24)
Reply
#2

Why you queried that 3 times? ..
Simply do a one big query, then try. and to save nicks use mysql_real_escapestring
Example:

pawn Код:
stock escpname(playerid)
{
    new escname[24], Pname[24];
    GetPlayerName(playerid, Pname, 24);
    mysql_real_escape_string(Pname, escname);
    return escname;
}
change PlayerName2 to escpname
Reply
#3

Quote:
Originally Posted by Jarnu
Посмотреть сообщение
Why you queried that 3 times? ..
Simply do a one big query, then try. and to save nicks use mysql_real_escapestring
Example:

pawn Код:
stock escpname(playerid)
{
    new escname[24], Pname[24];
    GetPlayerName(playerid, Pname, 24);
    mysql_real_escape_string(Pname, escname);
    return escname;
}
change PlayerName2 to escpname
sa-mp nicks only allow characters
Код:
0-9 a-z [] () $ @ . =
since quotes aren't allowed, it's kind of pointless to escape a username.

@OP, whenever you're having trouble with MySQL, enable debugging and read the mysql_log.txt. Or just print the query and see what's wrong with it.
Reply
#4

Quote:
Originally Posted by Jarnu
Посмотреть сообщение
Why you queried that 3 times? ..
Simply do a one big query, then try. and to save nicks use mysql_real_escapestring
Example:

pawn Код:
stock escpname(playerid)
{
    new escname[24], Pname[24];
    GetPlayerName(playerid, Pname, 24);
    mysql_real_escape_string(Pname, escname);
    return escname;
}
change PlayerName2 to escpname
didn't worked.
Reply
#5

Here you go

pawn Код:
new query[200], IP[16], playername[MAX_PLAYER_NAME];
    GetPlayerIp(playerid, IP, 16);
    format(query, sizeof(query), "INSERT INTO accounts (UserName, Password,kills, deaths, Rank, Level, Operator, TagAllowed, dRank, Score, PrestigeWeaponID1,PrestigeWeaponID2,PrestigeWeaponID3,PrestigeWeaponID4) VALUES('%s', SHA1('%s'), 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0 ,0)", GetPlayerName(playerid, playername, MAX_PLAYER_NAME), passwordstring);
    mysql_query(query);
    format(query, sizeof(query), "INSERT INTO accounts (CapturedZones,PistolSkills,SicPistolSkill,DeserteagleSkill,Shotgun,CombatShotgun,UziTec,Mp5,ak47,m4,Sniper,LastPromotionsDay,LastPromotionsMonth,LastPromotionsYear) VALUES(0, 0, 0, 0, 0,0,0,0,0,0,0,0,0,0,0,0)");
    mysql_query(query);
    format(query, sizeof(query), "INSERT INTO accounts (HiredDay, HiredMonth, HiredYear, CM, SiM, Money, IP) VALUES(0, 0, 0, 0, 0, 0,'%s')",IP);
    mysql_query(query);
    //We do not need to store or free a result as it
    //is not a select statement. We can now send the
    //client a registration success message and set the
    //Login variable to 1.
    SendClientMessage(playerid, -1, "You have been registered on this server!");
    PlayerInfo[playerid][LoggedIn] = 1;
Reply
#6

Quote:
Originally Posted by ViruZz
Посмотреть сообщение
Here you go

pawn Код:
new query[200], IP[16], playername[MAX_PLAYER_NAME];
    GetPlayerIp(playerid, IP, 16);
    format(query, sizeof(query), "INSERT INTO accounts (UserName, Password,kills, deaths, Rank, Level, Operator, TagAllowed, dRank, Score, PrestigeWeaponID1,PrestigeWeaponID2,PrestigeWeaponID3,PrestigeWeaponID4) VALUES('%s', SHA1('%s'), 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0 ,0)", GetPlayerName(playerid, playername, MAX_PLAYER_NAME), passwordstring);
    mysql_query(query);
    format(query, sizeof(query), "INSERT INTO accounts (CapturedZones,PistolSkills,SicPistolSkill,DeserteagleSkill,Shotgun,CombatShotgun,UziTec,Mp5,ak47,m4,Sniper,LastPromotionsDay,LastPromotionsMonth,LastPromotionsYear) VALUES(0, 0, 0, 0, 0,0,0,0,0,0,0,0,0,0,0,0)");
    mysql_query(query);
    format(query, sizeof(query), "INSERT INTO accounts (HiredDay, HiredMonth, HiredYear, CM, SiM, Money, IP) VALUES(0, 0, 0, 0, 0, 0,'%s')",IP);
    mysql_query(query);
    //We do not need to store or free a result as it
    //is not a select statement. We can now send the
    //client a registration success message and set the
    //Login variable to 1.
    SendClientMessage(playerid, -1, "You have been registered on this server!");
    PlayerInfo[playerid][LoggedIn] = 1;
what did you change?
same as PlayerName2(playerid) -.-
Reply
#7

Quote:
Originally Posted by V_LOPE
Посмотреть сообщение
what did you change?
same as PlayerName2(playerid) -.-
I advise you to save to the player names directly from the GetPlayerName function then a custom one. If your problem still occurs then its a problem in your MySQL columns
Reply
#8

Quote:
Originally Posted by ViruZz
Посмотреть сообщение
If your problem still occurs then its a problem in your MySQL columns
Name Type Length/Values1
UserName| Varchar / 24
Reply
#9

Bump.
Reply
#10

Set default values on your columns. You're only inserting 3 new variables.
Reply


Forum Jump:


Users browsing this thread: 3 Guest(s)