17.08.2011, 17:57
Hello,
I recently created a MySQL account management system, the only problem is that when a player registers, it inserts the data twice, so I get 2 rows of the exact same data. Im using dialogs, so I think the problem might be in OnDialogResponse, but idk. Heres my OnDialogResponse, maybe you guys can figure it out.
I recently created a MySQL account management system, the only problem is that when a player registers, it inserts the data twice, so I get 2 rows of the exact same data. Im using dialogs, so I think the problem might be in OnDialogResponse, but idk. Heres my OnDialogResponse, maybe you guys can figure it out.
Код:
public OnDialogResponse(playerid, dialogid, response, listitem, inputtext[]) { if(dialogid == D_ERR) return Kick(playerid); if(dialogid == D_REG) { if(!response) { SendClientMessage(playerid, COLOR_RED, "[SeaBotSYSTEM]: Exit button clicked. Closing connection."); return Kick(playerid); } if(response) { if(!strlen(inputtext)) { SendClientMessage(playerid, COLOR_RED, "[SeaBotSYSTEM]: Nothing entered. Closing connection."); return Kick(playerid); } CheckMySQL(); new qry[128], name[MAX_PLAYER_NAME]; GetPlayerName(playerid, name, MAX_PLAYER_NAME); format (qry, sizeof(qry), "INSERT INTO accounts (pName, pPass, pMoney) VALUES ('%s', md5('%s'), '5000')", name, inputtext); mysql_query(qry); new cprint[100]; format (cprint, sizeof(cprint), "[MySQL]: User %s registered successfully", name); print(cprint); PExist[playerid] = 1; new string[100]; format(string, 128, "[SeaBotSYSTEM]: Success! Welcome aboard %s. Remember that your password is %s, you'll need that later on!", name, inputtext); SendClientMessage(playerid, COLOR_SEAGREEN, string); PLog[playerid] = 1; return 1; } } if(dialogid == D_LOGIN) { if(!response) { SendClientMessage(playerid, COLOR_RED, "[SeaBotSYSTEM]: Exit button clicked. Closing connection."); return Kick(playerid); } if(response) { if(!strlen(inputtext)) { SendClientMessage(playerid, COLOR_RED, "[SeaBotSYSTEM]: Nothing entered. Closing connection."); return Kick(playerid); } CheckMySQL(); new qry[128], name[MAX_PLAYER_NAME]; GetPlayerName(playerid, name, MAX_PLAYER_NAME); format (qry, sizeof(qry), "SELECT * FROM accounts WHERE pName = '%s' AND pPass = md5('%s')", name, inputtext); mysql_query(qry); mysql_store_result(); if(!mysql_num_rows()) { ShowPlayerDialog(playerid, D_LOGIN, DIALOG_STYLE_INPUT, "Ocean View Trucking", "Welcome back! Please login below.", "Login", "Exit"); SendClientMessage(playerid, COLOR_RED, "[SeaBotSYSTEM] Incorrect password!"); return 0; } new row[128]; new field[15][32]; mysql_fetch_row_format(row, "|"); explode(row, field, "|"); mysql_free_result(); PInfo[playerid][pName] = strval(field[1]); PInfo[playerid][pMoney] = strval(field[3]); PInfo[playerid][pBank] = strval(field[4]); PInfo[playerid][pALevel] = strval(field[5]); PInfo[playerid][pHouse] = strval(field[6]); PInfo[playerid][pFines] = strval(field[7]); PInfo[playerid][pStars] = strval(field[8]); PInfo[playerid][pArctic] = strval(field[9]); PInfo[playerid][pDumper] = strval(field[10]); PInfo[playerid][pFuel] = strval(field[11]); PInfo[playerid][pCement] = strval(field[12]); PInfo[playerid][pArrests] = strval(field[13]); PInfo[playerid][pScore] = strval(field[14]); GivePlayerMoney(playerid, PInfo[playerid][pMoney]); SetPlayerScore(playerid, PInfo[playerid][pScore]); new string[100]; format(string, sizeof(string), "[SeaBotSYSTEM] Welcome back %s, you are now logged in!", name); SendClientMessage(playerid, COLOR_SEAGREEN, string); return 1; } } return 1; }