Mysql problem -
Urefeu - 02.07.2012
Hello
I've a little script for connecting to my server :
Код:
new query[128], data[256];
GetPlayerName(playerid, pPseudo[playerid], sizeof(pPseudo[]));
format(query, sizeof(query), "SELECT `password` FROM `members` WHERE `pseudo` = '%s'", pPseudo[playerid]);
mysql_query(query);
mysql_store_result();
if(mysql_fetch_field("password", pPassword[playerid])) {
new sConnexion[128];
format(sConnexion, sizeof(sConnexion), "{009FFB}Hello, {0032FB}%s !\n\n{009FFB}Please enter your password :", pPseudo[playerid]);
ShowPlayerDialog(playerid, 1, DIALOG_STYLE_PASSWORD, "Connexion", sConnexion, "Connexion", "Exit");
}
The problem is that when I go on this server, it is rebooted and the script doesn't function.
Here is mysql_log.txt :
[Mon Jul 02 18:43:52 2012] Connected (0) to root @ localhost via TCP/IP.
[Mon Jul 02 18:43:52 2012] MySQL Server Version 5.5.24-log.
[Mon Jul 02 18:44:26 2012] Function: mysql_query executed: "SELECT `password` FROM `members` WHERE `pseudo` = 'Urefeu'" with result: "0".
[Mon Jul 02 18:44:26 2012] Function: mysql_store_result executed with result: "1"
[Mon Jul 02 18:44:26 2012] Function: mysql_fetch_field executed.
Thanks in advance !
Urefeu
Respuesta: Mysql problem -
[DOG]irinel1996 - 02.07.2012
Try with this:
pawn Код:
new query[128], data[256];
GetPlayerName(playerid, pPseudo[playerid], MAX_PLAYER_NAME);
format(query, sizeof(query), "SELECT password FROM members WHERE pseudo = '%s'",pPseudo[playerid]);
mysql_query(query);
mysql_store_result();
if(mysql_num_rows())
{
if(mysql_fetch_field("password", pPassword[playerid]))
{
new sConnexion[128];
format(sConnexion, sizeof(sConnexion), "{009FFB}Hello, {0032FB}%s !\n\n{009FFB}Please enter your password :", pPseudo[playerid]);
ShowPlayerDialog(playerid, 1, DIALOG_STYLE_PASSWORD, "Connexion", sConnexion, "Connexion", "Exit");
}
}
Best regards!
Re: Mysql problem -
Urefeu - 02.07.2012
Hello !
I always have my error...
if(mysql_num_rows()) and if(mysql_fetch_field("password", pPassword[playerid])) do the same thing : the first check if there is a row in the result of the query and the second check if there is a password field (so nearly a row) in the result. Sorry for my bad english :P
Do you have an other idea ?
Thanks always !
Re: Mysql problem -
Urefeu - 02.07.2012
No one has ideas? It completely blocks me :/
Re: Mysql problem -
Urefeu - 03.07.2012
Please
Respuesta: Mysql problem -
[DOG]irinel1996 - 03.07.2012
Let me try something.
_____________________
EDIT:
This line gives me doubts:
pawn Код:
mysql_fetch_field("password", pPassword[playerid])
I think its parameters are:
pawn Код:
mysql_fetch_field(value, destination[]);
//---Example:
new save_here[40];
mysql_fetch_field(2, save_here);
I mean, you're using it wrong.
Are you using BlueG's MySQL plugin?
Try with this:
pawn Код:
new query[128], data[256];
GetPlayerName(playerid, pPseudo[playerid], sizeof(pPseudo[]));
format(query,128, "SELECT * FROM members WHERE pseudo = '%s' LIMIT 1", pseudo[playerid]);
mysql_query(query), mysql_store_result();
if(mysql_num_rows())
{
new sConnexion[128];
format(sConnexion, sizeof(sConnexion), "{009FFB}Hello, {0032FB}%s !\n\n{009FFB}Please enter your password :", pPseudo[playerid]);
ShowPlayerDialog(playerid, 1, DIALOG_STYLE_PASSWORD, "Connexion", sConnexion, "Connexion", "Exit");
} else {
//Register dialog here.
}
Re: Mysql problem -
Urefeu - 03.07.2012
Thank you very much, that functions !
Now, the problem is that when I do that, the server crash :
Код:
new query[128], data[256];
GetPlayerName(playerid, pPseudo[playerid], sizeof(pPseudo[]));
format(query,128, "SELECT * FROM members WHERE pseudo = '%s' LIMIT 1", pseudo[playerid]);
mysql_query(query), mysql_store_result();
if(mysql_num_rows())
{
new sConnexion[128];
mysql_fetch_field("password", pPassword[playerid]); // I have added this line
format(sConnexion, sizeof(sConnexion), "{009FFB}Hello, {0032FB}%s !\n\n{009FFB}Please enter your password :", pPseudo[playerid]);
ShowPlayerDialog(playerid, 1, DIALOG_STYLE_PASSWORD, "Connexion", sConnexion, "Connexion", "Exit");
} else {
//Register dialog here.
}
I use this plugin by StrickenKid :
https://sampwiki.blast.hk/wiki/MySQL_Plugin
The parameters are : mysql_fetch_field(const fieldname[], dest[], MySQL:handle)
What is wrong in my code ?
Here is an example of code with this plugin :
http://www.strickenkid.com/mysql_plugin/example.pwn
In the second /login, you can see that he do the same thing as me when the server crashed...
I don't understand :/
Respuesta: Mysql problem -
[DOG]irinel1996 - 03.07.2012
Can you show me pPassword array please?
Yes, I see, strange... Let's take a look at your variables.
Use
[pawn] tag please!
PD: "That functions" ? (functions = works) (That works) I understand you because I speak three languages. xD
_______________________________
EDIT:
Try this, as I saw StrickenKid uses a 256 cells array.
pawn Код:
new pPassword[MAX_PLAYERS][256];
Re: Mysql problem -
Urefeu - 03.07.2012
The strangest thing is that when I run the server and I connect, the server crash with the code of previous post.
By cons, when a friend logs on (her nickname is not in the database so it goes into the else who does anything yet) and after I connect, my script works perfectly for me to log ...
EDIT : new pPassword[MAX_PLAYERS][64];
Re: Mysql problem -
Urefeu - 03.07.2012
Here is mysql_log.txt :
Код:
[Tue Jul 03 18:52:29 2012] -------------------------
[Tue Jul 03 18:52:29 2012] Logging Started
[Tue Jul 03 18:52:29 2012] -------------------------
[Tue Jul 03 18:52:30 2012] Function: mysql_init executed with result: "0".
[Tue Jul 03 18:52:30 2012] Connected (0) to samp-rp @ localhost via TCP/IP.
[Tue Jul 03 18:52:30 2012] MySQL Server Version 5.5.24-log.
[Tue Jul 03 18:54:02 2012] Function: mysql_query executed: "SELECT * FROM members WHERE pseudo = 'MyFriend' LIMIT 1" with result: "0".
[Tue Jul 03 18:54:02 2012] Function: mysql_store_result executed with result: "1"
[Tue Jul 03 18:54:02 2012] Function: mysql_num_rows executed with result: "".
[Tue Jul 03 18:54:02 2012] Function: mysql_free_result executed.
[Tue Jul 03 18:54:52 2012] Function: mysql_query executed: "SELECT * FROM members WHERE pseudo = 'Urefeu' LIMIT 1" with result: "0".
[Tue Jul 03 18:54:52 2012] Function: mysql_store_result executed with result: "1"
[Tue Jul 03 18:54:52 2012] Function: mysql_num_rows executed with result: "".
[Tue Jul 03 18:54:52 2012] Function: mysql_fetch_field executed.
[Tue Jul 03 18:54:52 2012] Function: mysql_free_result executed.
[Tue Jul 03 19:17:17 2012] -------------------------
[Tue Jul 03 19:17:17 2012] Logging Started
[Tue Jul 03 19:17:17 2012] -------------------------
[Tue Jul 03 19:17:17 2012] Function: mysql_init executed with result: "0".
[Tue Jul 03 19:17:17 2012] Connected (0) to samp-rp @ localhost via TCP/IP.
[Tue Jul 03 19:17:17 2012] MySQL Server Version 5.5.24-log.
[Tue Jul 03 19:17:45 2012] Function: mysql_query executed: "SELECT * FROM members WHERE pseudo = 'Urefeu' LIMIT 1" with result: "0".
[Tue Jul 03 19:17:45 2012] Function: mysql_store_result executed with result: "1"
[Tue Jul 03 19:17:45 2012] Function: mysql_num_rows executed with result: "".
[Tue Jul 03 19:17:45 2012] Function: mysql_fetch_field executed.
You can see that when my friend logs on before me, my connection works. By cons, when I log in first, the script stops at mysql_fetch_field ... It's really strange ...