problem inserting a new row to a table.

Questions about the MySQL, PostgreSQL, and most other databases, as well as using it with PHP can be asked here.

Moderator: General Moderators

Post Reply
davidklonski
Forum Contributor
Posts: 128
Joined: Mon Mar 22, 2004 4:55 pm

problem inserting a new row to a table.

Post 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
davidklonski
Forum Contributor
Posts: 128
Joined: Mon Mar 22, 2004 4:55 pm

Post 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.
User avatar
markl999
DevNet Resident
Posts: 1972
Joined: Thu Oct 16, 2003 5:49 pm
Location: Manchester (UK)

Post 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');
Post Reply