Weird Error with inserting year into Table Field.

PHP programming forum. Ask questions or help people concerning PHP code. Don't understand a function? Need help implementing a class? Don't understand a class? Here is where to ask. Remember to do your homework!

Moderator: General Moderators

Post Reply
psychotomus
Forum Contributor
Posts: 487
Joined: Fri Jul 11, 2003 1:59 am

Weird Error with inserting year into Table Field.

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


}
psychotomus
Forum Contributor
Posts: 487
Joined: Fri Jul 11, 2003 1:59 am

Post by psychotomus »

i needed to change the year field into a varchar instead of tinyint.
User avatar
onion2k
Jedi Mod
Posts: 5263
Joined: Tue Dec 21, 2004 5:03 pm
Location: usrlab.com

Post by onion2k »

The overhead on the database would be smaller if you made it an int instead of a varchar.
psychotomus
Forum Contributor
Posts: 487
Joined: Fri Jul 11, 2003 1:59 am

Post by psychotomus »

well it wasnt working with int. so i had to make it a char.
Syranide
Forum Contributor
Posts: 281
Joined: Fri May 20, 2005 3:16 pm
Location: Sweden

Post 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).
Post Reply