Page 1 of 1

problem inserting a new row to a table.

Posted: Sat Apr 10, 2004 11:10 am
by davidklonski
Hello

I have the following table definition:

CREATE TABLE `session_info_tbl` (
`UserID` int(11) NOT NULL default '0',
`Expiration` timestamp(14) NOT NULL,
`IndividualsLastQuery` varchar(255) NOT NULL default '',
PRIMARY KEY (`UserID`)
) TYPE=MyISAM;

I am trying to add a new row to the table with the following command:

INSERT INTO session_info_tbl (UserID, Expiration, IndividualsLastQuery) VALUES ('test', 1081623606, '');

but for some reason the row that gets added is:
UserID: 0
Expiration: 00000000000000
IndividualsLastQuery:

What am I doing wrong?
I know the following the the MySQL spec:
Illegal DATETIME, DATE, or TIMESTAMP values are converted to the ``zero'' value of the appropriate type ('0000-00-00 00:00:00', '0000-00-00', or 00000000000000).
Why is my timestamp wrong? and even if it is wrong, why wasn't the userID field set appropriately?
I am doing it in PHP and mysql_query() returns true. So there was no error in the query.

thanks in advance

Posted: Sat Apr 10, 2004 11:20 am
by davidklonski
I don't belive there is an error in the table creation since I didn't create the create statement but MySQL Control Center created it for me.

When I tried this solution I got an error saying that a default value was missing for the IndividualsLastQuery column.

Posted: Sat Apr 10, 2004 11:26 am
by markl999
A MySQL timestamp isn't the same as a Unix timestamp, see http://dev.mysql.com/doc/mysql/en/DATETIME.html

Also your UserID is an INT field yet you are putting 'test' into it, which is why it's showing as 0.
You really want something like,
INSERT INTO session_info_tbl (UserID, Expiration, IndividualsLastQuery) VALUES (5, '2004-09-30', 'whatever here');