14.04.2015, 22:49
Quote:
Because MYSQL is hardcore coding for me. And i think theres no else solution that can solve my problem in my previous thread.
|
Basically when the gamemode connects you want to connect to the mySQL using the function: mysql_connect().
On register you want to create a new row, all the values you really should need to put in are the important values: name, password ect. You will want to use mysql_format() for this to INSERT. Reminder! For all user input strings you want to use '%e' instead of '%s', this will escape the string. If you don't you are vulnerable to injections. After that: mysql_tquery. Same applies to saving data!!
On login you want to SELECT from mySQL. You want to loop through each row in mySQL using cache_get_row_count(),
for(new i = 0; i < cache_get_row_count(); i++)
{
... load row inside here.
}
When loading data it's important that you fetch the player name from that row, match it, then check that the input password is the same! NOTE: encrypt the password the user inputs, and check it with an already encrypted password saved to mySQL.
When saving, you want to update a mySQL row. Below is an example,
mysql_format(connection_handle, string, sizeof(string), "UPDATE `tablename` SET `Money` = %d`WHERE `name`='%e'", player_money, player_name);
mysql_tquery(mysql_tquery(connection_handle, string, "", "");
connection_handle is the variable that stores the mysql connection: connection_handle = mysql_connect(...)
Do some research buddy. I have provided an example in a different context, the concept remains the same!