SA-MP Forums Archive
MySQL not working. - Printable Version

+- SA-MP Forums Archive (https://sampforum.blast.hk)
+-- Forum: SA-MP Scripting and Plugins (https://sampforum.blast.hk/forumdisplay.php?fid=8)
+--- Forum: Scripting Help (https://sampforum.blast.hk/forumdisplay.php?fid=12)
+--- Thread: MySQL not working. (/showthread.php?tid=490241)



MySQL not working. - Shetch - 25.01.2014

I have this code where a player gets kicked if he connects to the server without a registered nickname. Every time I connect, I het kicked although I am registered.

Код:
new query[128], name[MAX_PLAYER_NAME + 1];
GetPlayerName(playerid, name, sizeof(name));
mysql_format(mysql, query, sizeof(query), "SELECT * FROM `players` WHERE `name` = '%e'", name);
printf("QUERY: %s", query);
mysql_tquery(mysql, query, "", "");

new rows, fields;
cache_get_data(rows, fields);
if(rows == 0)
{
    MessageKick(playerid, COLOR_RED, "Error: You must register on our website before playing.");
    return 1;
}
else
{
    cache_get_field_content(0, "password", player[playerid][p_password], 129);
    ShowPlayerDialog(playerid, DIALOG_LOG_IN, DIALOG_STYLE_PASSWORD, COLOR_WHITE_EMBEDDED"Log In", COLOR_WHITE_EMBEDDED"Welcome to "COLOR_BLUE_EMBEDDED"Reality Role-Play"COLOR_WHITE_EMBEDDED"!\nLog In by typing in your password below.", "Confirm", "Cancel");
    player[playerid][p_log_in_tries] = 3;
}



Re: MySQL not working. - Ranshand - 25.01.2014

Change.
Код:
mysql_format(mysql, query, sizeof(query), "SELECT * FROM `players` WHERE `name` = '%e'", name);
To.
Код:
mysql_format(mysql, query, sizeof(query), "SELECT * FROM `players` WHERE `name` = '%s'", name);



Re: MySQL not working. - Shetch - 25.01.2014

Quote:
Originally Posted by Ranshand
Посмотреть сообщение
Change.
Код:
mysql_format(mysql, query, sizeof(query), "SELECT * FROM `players` WHERE `name` = '%e'", name);
To.
Код:
mysql_format(mysql, query, sizeof(query), "SELECT * FROM `players` WHERE `name` = '%s'", name);
The '%e' is there to prevent MySQL injection. The query is correct, there's something worng with reading the data recieved.


Re: MySQL not working. - iZN - 25.01.2014

pawn Код:
cache_get_data(rows, fields);
if(!rows)
{
    MessageKick(playerid, COLOR_RED, "Error: You must register on our website before playing.");
    return 1;
}
else
{
    cache_get_field_content(0, "password", player[playerid][p_password], 129);
    ShowPlayerDialog(playerid, DIALOG_LOG_IN, DIALOG_STYLE_PASSWORD, COLOR_WHITE_EMBEDDED"Log In", COLOR_WHITE_EMBEDDED"Welcome to "COLOR_BLUE_EMBEDDED"Reality Role-Play"COLOR_WHITE_EMBEDDED"!\nLog In by typing in your password below.", "Confirm", "Cancel");
    player[playerid][p_log_in_tries] = 3;
}



Re: MySQL not working. - Shetch - 25.01.2014

Quote:
Originally Posted by iZN
Посмотреть сообщение
pawn Код:
cache_get_data(rows, fields);
if(!rows)
{
    MessageKick(playerid, COLOR_RED, "Error: You must register on our website before playing.");
    return 1;
}
else
{
    cache_get_field_content(0, "password", player[playerid][p_password], 129);
    ShowPlayerDialog(playerid, DIALOG_LOG_IN, DIALOG_STYLE_PASSWORD, COLOR_WHITE_EMBEDDED"Log In", COLOR_WHITE_EMBEDDED"Welcome to "COLOR_BLUE_EMBEDDED"Reality Role-Play"COLOR_WHITE_EMBEDDED"!\nLog In by typing in your password below.", "Confirm", "Cancel");
    player[playerid][p_log_in_tries] = 3;
}
I'm pretty sure 'rows == 0' is the same as '!rows'. Tried it, doesn't work.


Re: MySQL not working. - iZN - 25.01.2014

Quote:
Originally Posted by Shetch
Посмотреть сообщение
I'm pretty sure 'rows == 0' is the same as '!rows'. Tried it, doesn't work.
Well, !row = row is not equal to and rows == 0 means rows equal to 0.

Try removing the 'return 1;'


Re: MySQL not working. - Shetch - 25.01.2014

Nevermind, I fixed it myself. Used 'mysql_query' insted of 'mysql_tquery'.