PDA

View Full Version : Mysql date saving problem


Dancev96
21/04/2014, 05:25 PM
Hi!
Recently i moved my server from saving in files to saving in databases.
Here is my code:

stock Zacuvajigrac(playerid)
{
// Zacuvajigrac
new playername3[MAX_PLAYER_NAME],query[300],makepl[500];
new y,m,d;
PlayerInfo[playerid][pDate] = getdate(y,m,d);
GetPlayerName(playerid, playername3, sizeof(playername3));
format(query, sizeof(query), "SELECT * FROM `players` WHERE `ime` = '%s'",playername3);
mysql_query(g_Handle, query);
if (cache_get_row_count()==0){
format(makepl, sizeof(makepl), "INSERT INTO `players`(`ime`, `lozinka`,`email`,`health`, `level`, `gmlevel`, `godini`, `kes`, `banka`, `lider`, `clen`, `model`,`data`) VALUES ('%s','%s','%.1f','%d','%d','%d','%d','%d','%d','% d','%d','%s', NOW())",
playername3,
PlayerInfo[playerid][pKey],
PlayerInfo[playerid][pEmail],
PlayerInfo[playerid][pHealth],
PlayerInfo[playerid][pLevel],
PlayerInfo[playerid][pGameMaster],
PlayerInfo[playerid][pAge],
PlayerInfo[playerid][pCash],
PlayerInfo[playerid][pAccount],
PlayerInfo[playerid][pLeader],
PlayerInfo[playerid][pMember],
PlayerInfo[playerid][pModel],
PlayerInfo[playerid][pDate]);
mysql_query(g_Handle, makepl);
}else{
format(query, sizeof(query), "UPDATE `players` SET `lozinka`='%s',`email`='%s',`health`='%.1f',`level `='%d',`donatorrank`='%d',`gmlevel`='%d',`godini`= '%d',`kes`='%d',`banka`='%d',`lider`='%d',`clen`=' %d',`model`='%d',`data`='%d' WHERE `ime`=''",
PlayerInfo[playerid][pKey],
PlayerInfo[playerid][pEmail],
PlayerInfo[playerid][pHealth],
PlayerInfo[playerid][pLevel],
PlayerInfo[playerid][pDonateRank],
PlayerInfo[playerid][pGameMaster],
PlayerInfo[playerid][pAge],
PlayerInfo[playerid][pCash],
PlayerInfo[playerid][pAccount],
PlayerInfo[playerid][pLeader],
PlayerInfo[playerid][pMember],
PlayerInfo[playerid][pModel],
PlayerInfo[playerid][pDate],
playername3);
mysql_query(g_Handle, query);
}
return 1;
}

This is the stock for saving the player.When i connect to the server and ingame edit the values everything works fine,except the date of the connect.
It doesn't save the date in the database.
Please help me if you can.

Ramoboss
21/04/2014, 06:03 PM
here it is i think :)


format(makepl, sizeof(makepl), "INSERT INTO `players`(`ime`, `lozinka`,`email`,`health`, `level`, `gmlevel`, `godini`, `kes`, `banka`, `lider`, `clen`, `model`,`data`) VALUES ('%s','%s','%.1f','%d','%d','%d','%d','%d','%d','% d','%d','%s', NOW())",


this NOW()) doesn't have his place, he does not do anything (unless fuck up your script)

Dancev96
21/04/2014, 06:08 PM
here it is i think :)


format(makepl, sizeof(makepl), "INSERT INTO `players`(`ime`, `lozinka`,`email`,`health`, `level`, `gmlevel`, `godini`, `kes`, `banka`, `lider`, `clen`, `model`,`data`) VALUES ('%s','%s','%.1f','%d','%d','%d','%d','%d','%d','% d','%d','%s', NOW())",


this NOW()) doesn't have his place, he does not do anything (unless fuck up your script)
I removed it but still doesn't work
Here is my new code:

stock Zacuvajigrac(playerid)
{
// Zacuvajigrac
new playername3[MAX_PLAYER_NAME],query[300],makepl[500];
new year, month,day;
GetPlayerName(playerid, playername3, sizeof(playername3));
format(query, sizeof(query), "SELECT * FROM `players` WHERE `ime` = '%s'",playername3);
mysql_query(g_Handle, query);
if (cache_get_row_count()==0){
format(makepl, sizeof(makepl), "INSERT INTO `players`(`ime`, `lozinka`,`email`,`health`, `level`, `gmlevel`, `godini`, `kes`, `banka`, `lider`, `clen`, `model`,`data`) VALUES ('%s','%s','%.1f','%d','%d','%d','%d','%d','%d','% d','%d','%d/%d/%04d')",
playername3,
PlayerInfo[playerid][pKey],
PlayerInfo[playerid][pEmail],
PlayerInfo[playerid][pHealth],
PlayerInfo[playerid][pLevel],
PlayerInfo[playerid][pGameMaster],
PlayerInfo[playerid][pAge],
PlayerInfo[playerid][pCash],
PlayerInfo[playerid][pAccount],
PlayerInfo[playerid][pLeader],
PlayerInfo[playerid][pMember],
PlayerInfo[playerid][pModel],
year,month,day);
mysql_query(g_Handle, makepl);
}else{
format(query, sizeof(query), "UPDATE `players` SET `lozinka`='%s',`email`='%s',`health`='%.1f',`level `='%d',`donatorrank`='%d',`gmlevel`='%d',`godini`= '%d',`kes`='%d',`banka`='%d',`lider`='%d',`clen`=' %d',`model`='%d',`data`='%d/%d/%04d' WHERE `ime`=''",
PlayerInfo[playerid][pKey],
PlayerInfo[playerid][pEmail],
PlayerInfo[playerid][pHealth],
PlayerInfo[playerid][pLevel],
PlayerInfo[playerid][pDonateRank],
PlayerInfo[playerid][pGameMaster],
PlayerInfo[playerid][pAge],
PlayerInfo[playerid][pCash],
PlayerInfo[playerid][pAccount],
PlayerInfo[playerid][pLeader],
PlayerInfo[playerid][pMember],
PlayerInfo[playerid][pModel],
year,month,day,
playername3);
mysql_query(g_Handle, query);
}
return 1;
}

Ramoboss
21/04/2014, 06:15 PM
so, i checked the code, here the fix :


format(query, sizeof(query), "INSERT INTO `players`(`ime`, `lozinka`,`email`,`health`, `level`, `gmlevel`, `godini`, `kes`, `banka`, `lider`, `clen`, `model`,`data`) VALUES ('%s','%s','%.1f','%d','%d','%d','%d','%d','%d','% d','%d', NOW())",


Past this code it will works, if it's not, try to replace NOW() by UNIX_TIMESTAMP()