Page 1 of 1

Weird Error with inserting year into Table Field.

Posted: Tue Jun 14, 2005 4:41 pm
by psychotomus
so the $themonth and $theyear output correctly giving 06 and 2005. when it inserts them into the table StatsByMonth, the month field is 06 and the year field is 127. Help?

Code: Select all

$themonth = date(&quote;m&quote;);
$theyear = date(&quote;Y&quote;);
print $themonth.'<br>'.$theyear.&quote;<br>&quote;;
$result = mysql_query( &quote;SELECT * FROM StatsByMonth WHERE month='$themonth' AND year='$theyear'&quote; );//
$row=mysql_fetch_array($result);	//Store Record Of Data in $row 


if ($row&#1111;'id'] == &quote;&quote;)
{
mysql_query (&quote;INSERT INTO StatsByMonth(Visitors, PageViews, Downloads, month, year) VALUES ('0', '0', '0', '$themonth', '$theyear')&quote;) 
		or die(mysql_error());
print 'boo';
}
else
{
print 'woo';


}

Posted: Tue Jun 14, 2005 5:09 pm
by psychotomus
i needed to change the year field into a varchar instead of tinyint.

Posted: Tue Jun 14, 2005 5:37 pm
by onion2k
The overhead on the database would be smaller if you made it an int instead of a varchar.

Posted: Tue Jun 14, 2005 5:44 pm
by psychotomus
well it wasnt working with int. so i had to make it a char.

Posted: Wed Jun 15, 2005 12:33 am
by Syranide
tinyint = -128 to 127
try reading the documentation

you need to go for mediumint or so, but I recommend saving year, month and the rest as one field (int).