PDA

View Full Version : Mysql help


sanrock
17/06/2012, 06:51 PM
The database gives like accounts with blank names,
and everyone who registers becomes level 5 at times for some reasons

gammode (first part)

mysql_connect(SQL_HOST, SQL_USER, SQL_DB, SQL_PASS);
mysql_query("CREATE TABLE IF NOT EXISTS playerdata(user VARCHAR(24), password VARCHAR(40), score INT(20), money INT(20), level INT(20), EXP INT(20), rank INT(20), kills INT(20), deaths INT(20), star INT(20), uc INT(20), IP VARCHAR(15) )");
mysql_debug(1);
return 1;


disconnect

format(query, sizeof(query), "UPDATE `playerdata` SET `score` = '%d', `kills` = '%d', `deaths` = '%d', `money` = '%d', `level` = '%d', `EXP` = '%d', `rank` = '%d', `star` = '%d', `uc` = '%d' WHERE `user` ='%s'", score, kills, deaths, money, AdminLevel[playerid], exxp, rank, Star[playerid], UC[playerid], pname);
mysql_query(query);
}


Dialog

//================================================== ==============//
// MySQL part //
//================================================== ==============//
if(dialogid == DIALOG_REGISTER)
{
if(response)
{
if(!strlen(inputtext) || strlen(inputtext) > 25)
{
SendClientMessage(playerid, COLOR_RED,"~r~Error: ~w~You must insert a password between 1-25 characters!");
ShowPlayerDialog(playerid, DIALOG_REGISTER, DIALOG_STYLE_INPUT, ""Blue"Please register",""White"Welcome to "Red""SERVER_NAME""White"!\n"White"In order to start playing, you have to register!\n\n"White"Please insert a password below:", "Register", "Cancel");
}
else if(strlen(inputtext) > 0 && strlen(inputtext) < 25)
{
new escpass[100];
mysql_real_escape_string(inputtext, escpass);
MySQL_Register(playerid, escpass);
}
}
if(!response)
{
SendClientMessage(playerid, COLOR_RED,"~r~Error: ~w~You must register before logging in!");
ShowPlayerDialog(playerid, DIALOG_REGISTER, DIALOG_STYLE_INPUT, ""Blue"Please register",""White"Welcome to "Red""SERVER_NAME""White"!\n"White"In order to start playing, you have to register!\n\n"White"Please insert a password below:", "Register", "Cancel");
}
}
if(dialogid == DIALOG_LOGIN)
{
if(!response)
{
SendClientMessage(playerid, COLOR_RED,"~r~Error: ~w~You must login before you spawn!");
ShowPlayerDialog(playerid, DIALOG_LOGIN, DIALOG_STYLE_INPUT, ""Blue"Please log-in", ""White"Welcome back to "Red""SERVER_NAME""White"!\n"White"In order to start playing, you have to log-in!\n\n"White"Please insert "Red"your"White" password below:", "Login", "Cancel");
}
if(response)
{
new query[200], pname[24], escapepass[100];
GetPlayerName(playerid, pname, 24);
mysql_real_escape_string(inputtext, escapepass);
format(query, sizeof(query), "SELECT `user` FROM `playerdata` WHERE `user` = '%s' AND password = `SHA1`('%s')", pname, escapepass);
mysql_query(query);
mysql_store_result();
new numrows = mysql_num_rows();
if(numrows == 1) MySQL_Login(playerid);
if(!numrows)
{
ShowPlayerDialog(playerid, DIALOG_LOGIN, DIALOG_STYLE_INPUT, ""Blue"Please log-in", ""White"Welcome back to "Red""SERVER_NAME""White"!\n"White"In order to start playing, you have to log-in!\n\n"White"Please insert "Red"your"White" password below:", "Login", "Cancel");
SendClientMessage(playerid, COLOR_RED,"~r~Error: ~w~Incorrect password!");
}
mysql_free_result();
}
}
return 1;
}


connect

MoneyGiven[playerid] = -1;
JustLogged[playerid] = 0;
new query[300], pname[24];
GetPlayerName(playerid, pname, 24);
format(query, sizeof(query), "SELECT IP FROM `playerdata` WHERE `user` = '%s' LIMIT 1", pname);
mysql_query(query);
mysql_store_result();
new rows = mysql_num_rows();
if(!rows)
{
ShowPlayerDialog(playerid, DIALOG_REGISTER, DIALOG_STYLE_INPUT, ""Blue"Please register",""White"Welcome to "Red""SERVER_NAME""White"!\n"White"In order to start playing, you have to register!\n\n"White"Please insert a password below:", "Register", "Cancel");
}
if(rows == 1)
{
new IP[2][15];
mysql_fetch_field_row(IP[0],"IP");
GetPlayerIp(playerid, IP[1], 15);
if(strlen(IP[0]) != 0 && !strcmp(IP[0], IP[1], true))
{
MySQL_Login(playerid);
}
else if(!strlen(IP[0]) || strcmp(IP[0], IP[1], true))
{
ShowPlayerDialog(playerid, DIALOG_LOGIN, DIALOG_STYLE_INPUT, ""Blue"Please log-in", ""White"Welcome back to "Red""SERVER_NAME""White"!\n"White"In order to start playing, you have to log-in!\n\n"White"Please insert "Red"your"White" password below:", "Login", "Cancel");
IsRegistered[playerid] = 1;
}
}
mysql_free_result();
return 1;
}


Spawn

{
//================================================== ==============//
// MySQL part //
//================================================== ==============//
if(!Logged[playerid])
{
if(!IsRegistered[playerid])
{
ShowPlayerDialog(playerid, DIALOG_REGISTER, DIALOG_STYLE_INPUT, ""Blue"Please register",""White"Welcome to "Red""SERVER_NAME""White"!\n"White"In order to start playing, you have to register!\n\n"White"Please insert a password below:", "Register", "Cancel");
return 0;
}
if(IsRegistered[playerid] == 1)
{
ShowPlayerDialog(playerid, DIALOG_LOGIN, DIALOG_STYLE_INPUT, ""Blue"Please log-in", ""White"Welcome back to "Red""SERVER_NAME""White"!\n"White"In order to start playing, you have to log-in!\n\n"White"Please insert "Red"your"White" password below:", "Login", "Cancel");
return 0;
}
}
return 1;
}



Why does it do that?

sanrock
18/06/2012, 02:52 PM
Bump

sanrock
18/06/2012, 06:15 PM
Bump please

sanrock
18/06/2012, 07:29 PM
COMMON HELP PLEASE

FUNExtreme
18/06/2012, 07:32 PM
Do you set the variable to 0 when the player connects. If not, it could be possible that for example: Player 1 with level 5 admin is in the server, that player then leaves and someone else comes in with the same playerid. That new player will then have level 5 because it wasn't reset.
Schematic:
Player 1 (ID: 0) (Level 5 admin)
Player 1 (ID: 0) leaves
Player 2 (ID: 0) joins
Player 2 (ID: 0) (Is level 5 admin because it wasn't reset from Player 1)

If that isn't the problem, I'll look a little more into your script