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

Have a question or a suggestion about a 3rd party addon module or plugin?
Let us know here.
Locked
badfrog@w00tz!

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

Post 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?
Last edited by badfrog@w00tz! on Sat Feb 24, 2007 12:13 am, edited 1 time in total.
calguy1000
Support Guru
Support Guru
Posts: 8169
Joined: Tue Oct 19, 2004 6:44 pm
Location: Fernie British Columbia, Canada

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

Post by calguy1000 »

replace

Code: Select all

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

Code: Select all

$tstamp = trim($db->DBTimeStamp(time()),"'");	
Follow me on twitter
Please post system information from "Extensions >> System Information" (there is a bbcode option) on all posts asking for assistance.
--------------------
If you can't bother explaining your problem well, you shouldn't expect much in the way of assistance.
badfrog@w00tz!

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

Post by badfrog@w00tz! »

Yeah, that worked. Thanks to the person who suggested it in chat, whoever that was ;)
Locked

Return to “Modules/Add-Ons”