Register System
#1

Hello.

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;
}
In OnGameModeInit :
Код:
MysqlConnect();
In OnPlayerConnect :
Код:
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;
In OnDialogResponse :
Код:
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;
	}
In my console, I have : [MYSQL] : Sucessfull !

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)");
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 !
Reply
#2

You have the Newest Version of MySQL ?
Reply
#3

Yes, I've download the last !
Reply
#4

It works, I was confused 'and `<.

Despite that I still have a problem:

This code does not work. Why ?

Код:
 format(query, 200, "INSERT INTO `member`(pseudo, password, score, cash) VALUES('%s', '%s', 20000, 0)", playerName, password);
Thanks !
Reply
#5

Quote:
Originally Posted by Urefeu
Посмотреть сообщение
It works, I was confused 'and `<.

Despite that I still have a problem:

This code does not work. Why ?

Код:
 format(query, 200, "INSERT INTO `member`(pseudo, password, score, cash) VALUES('%s', '%s', 20000, 0)", playerName, password);
Thanks !
Do you get any errors? If not, do you have a database called `member`? If you have, what is exactly the problem?
Reply
#6

change mysql_ping() == 1 to mysql_ping != 0
Reply
#7

The table exists and I have no errors.

It makes no difference to mysql_ping () as well.

The problem is that no line is inserted into the DB!
Reply
#8

And you do connect to the database? [Sorry, didn't read the whole page if you did post it already]
Reply
#9

put this somewhere in script, enter the game and see the console
pawn Код:
public OnQueryError(errorid, error[], resultid, extraid, callback[], query[], connectionHandle) {
printf("EID: %d | Error: %s | Query: %s", errorid, error, query);
return 1;
}
Reply
#10

Yes, I do connect to the database !

No sentence in the console, so there's no error: o

And nothing in the DB
Reply


Forum Jump:


Users browsing this thread: 1 Guest(s)