Mysql RegDate
#1

Hello how can i make a Registrations Date here ist my Register script:

Код:
public OnDialogResponse(playerid, dialogid, response, listitem, inputtext[])
{
    if(dialogid == 14600)
    {
       if(response)
       {
            if(!strlen(inputtext))
            {
                ShowPlayerDialog(playerid, 14600, DIALOG_STYLE_INPUT , "Register", "This account is not registered, please register!", "OK", "Cancel");
                SendClientMessage(playerid, 0xF60000AA, "Please enter a password");
            }
            mysql_real_escape_string(inputtext, escpass);
			WP_Hash(largestring, sizeof(largestring), escpass);
            GetPlayerIp(playerid, PIP, 50); 
            format(Query, sizeof(Query), "INSERT INTO `playerinfo` (`user`, `password`, `kills`, `deaths`, `score`, `money`, `IP`, `adminlvl`) VALUES ('%s', '%s', 0, 0, 0, 0, '%s', 0)", escpname(playerid), largestring, PIP);
            mysql_query(Query); 
            GameTextForPlayer(playerid, "~g~Registered", 2000, 3);
            SendClientMessage(playerid, 0x0000D9AA, "Registered and Logged into your account!");
            SetPVarInt(playerid, "Logged", 1);
        }
    }
I wnat only save the Registrations Date in the Mysql Databas from the player
Reply
#2

First you need to add this:
new year, month, day;
getdate(year, month, day);

Then do something like this:
"INSERT INTO 'playerinfo' ('regdate') VALUES ('%d-%d-%d')", year, month, day);

I think you will understand
Reply
#3

thanks and in the "CREATE TABLE IF NOT EXISTS" must i add this? "regdate VARCHAR(10)" or is that wrong?
Reply
#4

Yea, it's okay.
Reply
#5

now when i register a account, and reelog, the account doesnt exist. what is wrong?
Reply
#6

i have now

Код:
mysql_query("CREATE TABLE IF NOT EXISTS playerinfo(user VARCHAR(24), password VARCHAR(400),killss INT(20),deaths INT(20), score INT(20), money INT(20), IP VARCHAR(16),adminlvl INT(5),hoursplayed INT(20), minutesplayed INT(20),ratio VARCHAR(5),regdate VARCHAR(10))");
	mysql_debug(1);
and in the register:

Код:
           	new year, month, day;
			getdate(year, month, day);
            mysql_real_escape_string(inputtext, escpass);
			WP_Hash(largestring, sizeof(largestring), escpass);
            GetPlayerIp(playerid, PIP, 50);
            format(Query, sizeof(Query), "INSERT INTO `playerinfo` (`user`, `password`, `killss`, `deaths`, `score`, `money`, `IP`, `adminlvl`,`ratio`, `regdate`) VALUES ('%s', '%s', 0, 0, 0, 0, '%s', 0,'%f','%s','%d/%d/%d')", escpname(playerid), largestring, PIP,(Float:PlayerInfo[playerid][killss] / Float:PlayerInfo[playerid][deaths]),day,month,year);
            mysql_query(Query);
what is wrong, before the getdate script, It was working 100 percent
Reply
#7

Make sure table "regdate" exists
Reply
#8

yes its exist!
Reply
#9

This is just plain horrible. Your mistake should be easy to fix as you have an unnecessary '%s' before the '%d/%d/%d' field in the INSERT query.

But we should also probably go over optimizing your MySQL table and by that, decreasing the size and execution speed of queries.

I will go over your field syntax one by one:
password VARCHAR(400) - Whirlpool (AFAIK) gives a 128-character hash. So decrease this size to 129 (leaving room for the null character)
killss INT(20) - Why is this field named KILLSS, when the proper version would be KILLS, anyways? A INT field allows you to store values from -2147483647 to 2147483647. And GOD will I kill myself if a player once reaches 2147483647 kills or has a negative kills value! Change this to unsigned smallint (or mediumint in case a player has chances of getting more than 65535 kills).
The same goes for the deaths field.
I don't know the highest score value possible in SA-MP, but I still suppose a MEDIUMINT would be more appropriate.
adminlevel INT(5) is just horrible again. I very much doubt that you have an admin level with the value of 2147483647. And actually, I am pretty sure that your admin levels do not go past 127 (signed TINYINT) or 255 (unsigned TINYINT). Now if you change it to TINYINT, it will take 3 bytes less space to store this information. In a database with tons of entries, this will actually make quite a difference.
hoursplayed INT(20) is an interesting sight! I doubt we'll see a player who is online for 245000 years, so feel free to decrease this value to something smaller. Also, this raises a question for me: what would be the best method to increment this value? What if a player joins, is online for 10 minutes and then leaves, comes back and repeats the situation at least 6 times? No chance that the online time will increase.
ratio VARCHAR(5)... Why do you have this as a string? Use a FLOAT instead.

And another 2 suggestions:
1. Create DEFALUT values for the fields, so you don't have to specify the values in the INSERT query itself.
2. Add INDEX(es) to the table.

I hope you find this piece of writing at least a bit useful and can, in the future, design your fields with a better touch!
Reply
#10

thanks it works!

now when i make /stats



format(string,sizeof string,"Register Date: {FF0000}%d/%d/%d{FF8000}",PlayerInfo[playerid][regdate]);
SendClientMessage(playerid,0xFF8200FF,string);

Only comes "23//" in the chat ingame what is wrong?
Reply


Forum Jump:


Users browsing this thread: 1 Guest(s)