Page 1 of 1

SQL Insert question

Posted: Fri Jul 28, 2006 12:02 pm
by klarinetking
Hi,

I'm wondering why this query won't work:

Code: Select all

$sql = "INSERT INTO `sessions` (`session_id`, `last_active`, `user_id`)
			VALUES ('$this->sid', '$this->time', '29')";
I recieve the error: Out of range value adjusted for column 'last_active' at row 1

last_active is a mediumint(12). I've even tried it as an unsigned field, but it won't work. The value I'm trying to insert is simply the result from time();

Any help would be appreciated.

klarinetking[/syntax]

Posted: Fri Jul 28, 2006 7:53 pm
by klarinetking
Alright, figured this one out.

Made last_active bigint, and used UNIX_TIMESTAMP() as the time to be inserted into the DB.

klarinetking

Posted: Fri Jul 28, 2006 8:06 pm
by bdlang
Just as an FYI, if $this->time is an INT (which I assume, since it's the return of PHP
s time() function), don't wrap it in quotes. The same goes for the value '29' in your query. If an INT or FLOAT type is going into one of those types of columns, leave off the quote; if it's supposed to be a string literal, wrap it.


You might want to look at the actual value of $this->time just in case.

Posted: Fri Jul 28, 2006 8:15 pm
by klarinetking
Yeah,

Actually I think the problem was the field size. Anyway, UNIX_TIMESTAMP() does it all automatically, and that's even better. And yeah, I learned about the quotes the hard way (spending two hours fiddling with it so it would insert).

klarinetking