Page 1 of 1

Custom module INSERT, dates always show up as 0000-00-00...

Posted: Sat Feb 24, 2007 12:11 am
by badfrog@w00tz!
So I'm using HitCounter as a guide to developing a "referral" module of sorts, to track linkbacks from other places. I have everything working splendidly, except my date field (MySQL 4.1.21-standard on Linux) always contains "0000-00-00 00:00:00"

As I said, I'm "inspiring" myself from HitCounter, so this is the relevant code:

Code: Select all

$ip = getenv("REMOTE_ADDR");
//log the hit as a referral
	$newid = $db->GenID( cms_db_prefix()."module_referrals_seq");
	$agent = $_SERVER["HTTP_USER_AGENT"];
	$referrer = "none";
	if( isset($HTTP_REFERER))
		$referrer=$HTTP_REFERER; 
	$tstamp = trim($db->DBTimeStamp(time()));	
	
	$q = "INSERT INTO ".cms_db_prefix()."module_referrals 
	(referral_id, referral_cd, source_ip, url, date, user_agent) 
	VALUES (?,?,?,?,?,?)";
	$dbresult = $db->Execute( $q, array( $newid, $code, $ip, $referrer, $tstamp, $agent));
//some error checks omitted for brevity
echo "<!-- Referral added for $code, $ip, $tstamp -->";
When I test this, I get the following output on the page:


and the record is created correctly, except date always contains 0000-00-00 00:00:00. I'm not sure where to go from here, and I must admit I haven't verified that HitCounter inserts a proper date. Any ideas?

Re: Custom module INSERT, dates always show up as 0000-00-00...

Posted: Sat Feb 24, 2007 1:18 am
by calguy1000
replace

Code: Select all

$tstamp = trim($db->DBTimeStamp(time()));	
with

Code: Select all

$tstamp = trim($db->DBTimeStamp(time()),"'");	

Re: Custom module INSERT, dates always show up as 0000-00-00...

Posted: Wed Feb 28, 2007 11:29 pm
by badfrog@w00tz!
Yeah, that worked. Thanks to the person who suggested it in chat, whoever that was ;)