Mysql Register System
#1

So heres my code for registering a player, i have more things to save, so how to make these into 2-3 lines with using other strings?
pawn Код:
format(string, sizeof(string), "INSERT INTO `players` ( `Name` , `Password`, `Money` , `Bank` , `Level` ,`RPoints` ,`Warns` ,`Job` ,`Banned` ,`Kills` , `Deaths`, `Faction`, `LastIP`, `rankname` `groupID`) VALUES ('%s', '%s', '%d', '%d', '%d', '%d', '%d', '%s', '%d', '%d', '%d','%s','%s', '%s' '%d')",
        PlayerName(playerid), PlayerTemp[playerid][password], PlayerTemp[playerid][sm], PlayerInfo[playerid][bank], PlayerInfo[playerid][playerlvl], PlayerInfo[playerid][rpoints], PlayerInfo[playerid][warns], PlayerInfo[playerid][job], PlayerInfo[playerid][banned], PlayerInfo[playerid][kills], PlayerInfo[playerid][deaths] ,PlayerInfo[playerid][PTeamName], PlayerTemp[playerid][IP], PlayerInfo[playerid][rankname], PlayerTemp[playerid][groupID]);
        mysql_query(string);
Reply
#2

Quote:
Originally Posted by MadafakaPro
Посмотреть сообщение
So heres my code for registering a player, i have more things to save, so how to make these into 2-3 lines with using other strings?
pawn Код:
format(string, sizeof(string), "INSERT INTO `players` ( `Name` , `Password`, `Money` , `Bank` , `Level` ,`RPoints` ,`Warns` ,`Job` ,`Banned` ,`Kills` , `Deaths`, `Faction`, `LastIP`, `rankname` `groupID`) VALUES ('%s', '%s', '%d', '%d', '%d', '%d', '%d', '%s', '%d', '%d', '%d','%s','%s', '%s' '%d')",
        PlayerName(playerid), PlayerTemp[playerid][password], PlayerTemp[playerid][sm], PlayerInfo[playerid][bank], PlayerInfo[playerid][playerlvl], PlayerInfo[playerid][rpoints], PlayerInfo[playerid][warns], PlayerInfo[playerid][job], PlayerInfo[playerid][banned], PlayerInfo[playerid][kills], PlayerInfo[playerid][deaths] ,PlayerInfo[playerid][PTeamName], PlayerTemp[playerid][IP], PlayerInfo[playerid][rankname], PlayerTemp[playerid][groupID]);
        mysql_query(string);
That's easy, you can either re-use your current "string" or create new variables.
An example:
pawn Код:
//Re-use:
format(string, sizeof(string), "INSERT INTO `players` ( `Name`) VALUES ('%s')",  PlayerName(playerid));
mysql_query(string);
format(string, sizeof(string), "INSERT INTO `players` ( `Password`) VALUES ('%s')",  PlayerTemp[playerid][password]);
mysql_query(string);


//and so on

//New variables:

format(string, sizeof(string), "INSERT INTO `players` ( `Name`) VALUES ('%s')",  PlayerName(playerid));
mysql_query(string);

new string_2[50];
format(string_2, sizeof(string_2), "INSERT INTO `players` ( `Password`) VALUES ('%s')",  PlayerTemp[playerid][password]);
mysql_query(string_2);

//and so on
Hope you understand what I mean
Reply
#3

I did it like this but its still not working :
pawn Код:
format(string, sizeof(string), "INSERT INTO `players` ( `Name` , `Password`, `Money` , `Bank` , `Level` ,`RPoints` ,`Warns` ,`Job` ,`Banned` ,`Kills` , `Deaths`, `Faction`, `LastIP`, `rankname`) VALUES ('%s', '%s', '%d', '%d', '%d', '%d', '%d', '%s', '%d', '%d', '%d','%s','%s', '%s')",
        PlayerName(playerid), PlayerTemp[playerid][password], PlayerTemp[playerid][sm], PlayerInfo[playerid][bank], PlayerInfo[playerid][playerlvl], PlayerInfo[playerid][rpoints], PlayerInfo[playerid][warns], PlayerInfo[playerid][job], PlayerInfo[playerid][banned], PlayerInfo[playerid][kills], PlayerInfo[playerid][deaths] ,PlayerInfo[playerid][PTeamName], PlayerTemp[playerid][IP], PlayerInfo[playerid][rankname]);
        format(string, sizeof(string),"INSERT INTO `players` ( `groupID`, `groupName`, `groupLeader` ) VALUES ( '%d', '%s', '%s' )", PlayerTemp[playerid][groupID], PlayerTemp[playerid][groupName], PlayerTemp[playerid][groupLeader]);
         mysql_query(string);
Reply
#4

I don't really get what you mean, registering a player you should only Insert their Name, Password. on saving you need to use UPDATE not INSERT INTO

EDITED:

pawn Код:
//Registering//
new
    string [ 128 ]
;

format(string, sizeof(string), "INSERT INTO `players` ( Name , Password ) VALUES ( '%s', '%s' )",
PlayerName( playerid ), PlayerTemp[ playerid ][ password ]);
mysql_query(string);

//Saving//
new
    string [ 528 ] // change the string value if this is not enough.
;
format( string, sizeof ( string ), "UPDATE `players` SET `Money` = %i , `Bank` = %i , `Level` = %i ,`RPoints` = %i ,`Warns` = %i ,`Job` = %i ,`Banned` = %i , \
`Kills` = %i, `Deaths` = %i, `Faction` = %i, `LastIP` = '%s' , `rankname` = '%s' WHERE `Username` = '%s'"
,
PlayerTemp[playerid][sm], PlayerInfo[playerid][bank], PlayerInfo[playerid][playerlvl], PlayerInfo[playerid][rpoints], PlayerInfo[playerid][warns], PlayerInfo[playerid][job],
PlayerInfo[playerid][banned], PlayerInfo[playerid][kills], PlayerInfo[playerid][deaths] ,PlayerInfo[playerid][PTeamName], PlayerTemp[playerid][IP], PlayerInfo[playerid][rankname], PlayerName(playerid));
format( string, sizeof ( string ), "UPDATE `players` SET `groupID` = %i , `groupName` = '%s' , `groupLeader` = '%s'",
PlayerTemp[playerid][groupID], PlayerTemp[playerid][groupName], PlayerTemp[playerid][groupLeader]);
Reply


Forum Jump:


Users browsing this thread: 1 Guest(s)