SA-MP Forums Archive
Register System - 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)
+---- Forum: Help Archive (https://sampforum.blast.hk/forumdisplay.php?fid=89)
+---- Thread: Register System (/showthread.php?tid=277153)



Register System - Urefeu - 16.08.2011

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 !


Re: Register System - ElieJabbour - 17.08.2011

You have the Newest Version of MySQL ?


Re : Register System - Urefeu - 17.08.2011

Yes, I've download the last !


Re : Register System - Urefeu - 17.08.2011

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 !


Re: Re : Register System - KingTurtle - 17.08.2011

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?


Re: Register System - CoaPsyFactor - 17.08.2011

change mysql_ping() == 1 to mysql_ping != 0


Re : Register System - Urefeu - 17.08.2011

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!


Re: Register System - KingTurtle - 17.08.2011

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


Re: Register System - System64 - 17.08.2011

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;
}



Re : Register System - Urefeu - 17.08.2011

Yes, I do connect to the database !

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

And nothing in the DB