16.08.2011, 17:17
(
Последний раз редактировалось Urefeu; 17.08.2011 в 08:27.
)
Hello.
I am creating a registration system works with MySql.
Here is my code :
To connect to the database
In OnGameModeInit :
In OnPlayerConnect :
In OnDialogResponse :
In my console, I have : [MYSQL] : Sucessfull !
When I Connect, I've : "? row"
I tried a query like that, just after the MysqlConnect(); :
No line has come to add in my database.
Do you have a solution to run the registration system, and run queries?
Thank you very much !
I am creating a registration system works with MySql.
Here is my code :
To connect to the database
Код:
forward MysqlConnect(); public MysqlConnect() { mysql_debug(1); mysql_connect("***", "***", "***", "***"); if(mysql_ping() == 1) { printf("[MYSQL] : Sucessfull !"); } else { printf("[MYSQL][ERROR] : ERROR !"); } return 1; }
Код:
MysqlConnect();
Код:
new query[400], playerName[126]; GetPlayerName(playerid, playerName, 126); format(query, 400, "SELECT * FROM 'sab_members' WHERE pseudo = '%s' LIMIT 1", playerName); mysql_query(query); mysql_store_result(); new rows = mysql_num_rows(); if(rows == 0) { // Inscription new string_register[256]; format(string_register, 256, "Welcome, %s ! Check a password :", playername); ShowPlayerDialog(playerid, 348, DIALOG_STYLE_INPUT, "Register", string_register, "Register", "Exit"); SendClientMessage(playerid, INFO, "0 row"); } else if(rows == 1) { // Connexion SendClientMessage(playerid, INFO, "1 row"); } else { SendClientMessage(playerid, INFO, "? row"); } mysql_free_result(); return 1;
Код:
if(dialogid == 348) { // Inscription new string_register[256]; if(response) { if(!strlen(inputtext) || strlen(inputtext) < 4 || strlen(inputtext) > 30) { format(string_register, 256, "Error ! Check a password :"); ShowPlayerDialog(playerid, 348, DIALOG_STYLE_INPUT, "Register", string_register, "Register", "Exit"); } else { new password[30], query[200], playerName[126], string[126]; mysql_real_escape_string(inputtext, password); GetPlayerName(playerid, playerName, 126); format(query, 200, "INSERT INTO member(pseudo, password, score, cash) VALUES('%s', '%s', 20000, 0)", playerName, password); mysql_query(query); format(string, 126, "You are register on this server, %s !", playerName); SendClientMessage(playerid, SUCCESS, string); } } if(!response) { format(string_register, 256, "Error ! Check a password :"); ShowPlayerDialog(playerid, 348, DIALOG_STYLE_INPUT, "Register", string_register, "Register", "Exit"); } return 1; }
When I Connect, I've : "? row"
I tried a query like that, just after the MysqlConnect(); :
Код:
mysql_query("INSERT INTO 'members'(pseudo, password, score, cash) VALUES('test', 'test', 0, 10000)");
Do you have a solution to run the registration system, and run queries?
Thank you very much !