SA-MP Forums Archive
[HELP]Datetime mysql table - 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)
+--- Thread: [HELP]Datetime mysql table (/showthread.php?tid=352311)



[HELP]Datetime mysql table - TheBluec0de - 19.06.2012

I use mysql plugin BlueG - version R6

I have the problem:

Pawn code:

PHP код:
new year, month, day, hour, minute, second;
getdate(year, month, day), gettime(hour, minute, second);
format(query, sizeof(query), "INSERT INTO `%s` (`Name`, `Password`, `Ip`, `Date_Registration`, `Money`, `Score`, `Kills`, `Deaths`) VALUES('%s', md5('%s'), '%s', '%d/%d/%04d' '%02d:%02d:%02d', 0, 0, 0, 0)", TABLE_NAME, name(playerid), inputtext, ip(playerid), day, month, year, hour, minute, second);
mysql_query(query); 
The problem is in ... Date_Registration

MySQL Debug:

PHP код:
[14:47:25] CMySQLHandler::Query(INSERT INTO `Users` (`Name`, `Password`, `Ip`, `Date_Registration`, `Money`, `Score`, `Kills`, `Deaths`) VALUES('Test', md5('testpass'), '127.0.0.1', '19/6/2012' '14:47:25', 0, 0, 0, 0)) - Successfully executed. 
Database:

PHP код:
CREATE TABLE `users` (
`
Name` varchar(24) NOT NULL,
`
Password` varchar(32) NOT NULL,
`
Ip` varchar(16) NOT NULL,
`
Date_Registration` datetime NOT NULL,
`
Money` int(10) NOT NULL,
`
Score` int(10) NOT NULL,
`
Kills` int(10) NOT NULL,
`
Deaths` int(10) NOT NULL )
ENGINE=InnoDB DEFAULT CHARSET=latin1; 
In the database save the date in : 0000-00-00 00:00:00 .... why ?


Re: [HELP]Datetime mysql table - Vince - 19.06.2012

Instead of your variables, insert one of these MySQL functions (literal): NOW() or UNIX_TIMESTAMP(). Not sure if any of these work, as I always use plain unix timestamps (https://sampforum.blast.hk/showthread.php?tid=254915).

So your query will look like:
PHP код:
INSERT INTO `%s` (`Name`, `Password`, `Ip`, `Date_Registration`, `Money`, `Score`, `Kills`, `Deaths`) VALUES('%s', md5('%s'), '%s', NOW(), 0, 0, 0, 0); 



Re: [HELP]Datetime mysql table - TheBluec0de - 19.06.2012

Quote:
Originally Posted by Vince
Посмотреть сообщение
Instead of your variables, insert one of these MySQL functions (literal): NOW() or UNIX_TIMESTAMP(). Not sure if any of these work, as I always use plain unix timestamps (https://sampforum.blast.hk/showthread.php?tid=254915).

So your query will look like:
PHP код:
INSERT INTO `%s` (`Name`, `Password`, `Ip`, `Date_Registration`, `Money`, `Score`, `Kills`, `Deaths`) VALUES('%s', md5('%s'), '%s', NOW(), 0, 0, 0, 0); 
Thanks