Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations gkittelson on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

Insert Date Into DB USING SQL 3

Status
Not open for further replies.

vivilady

Programmer
Mar 5, 2005
36
GB
Hi, can somebody please help. I am trying to insert into an access db using the following sql statement

$rs = $conn->Execute("Insert into commentTable(topic, comment, user, date) values('$topic', '$comment', '$user', NOW())");

but the line is giving a parser error. Now I have debug it down and found out that is the date part that is giving the error, but I can't seem to know why it is giving this error.

$rs = $conn->Execute("Insert Into commentTable(date) Values (Now())");

that dont work neither.

Please any suggestions???
 
And what is the type of 'date' column..?
Also it is recommended not to use column name with certain keywords like date etc..
Try renaming the date name to something.

--------------------------------------------------------------------------
I never set a goal because u never know whats going to happen tommorow.
 
i would suggest using gmdate() to get the date value:

$datelog = gmdate("Y-m-d");
$rs = $conn->Execute("Insert Into commentTable(datelog) Values ('$datelog')");


like spookie said make sure your column type is set to date or datetime if you want the time in there as well. Also, like spookie said, try not to use date as the column name as this can cause problems sometimes..

Hope this helps
 
Thank you guy!!! I've changed the date column in the db to something else and it work! well kind of... Here is the next problem now

I checked the DB and the date looks fine there but when I echo it out it shows like this
1110288534

here is the echo code

while (!$Recordset1->EOF) {
$maindates = $Recordset1->Fields("maindate");

echo ".$maindates->value.";

$Recordset1->MoveNext();
}

The result on screen like said is: 1110288534 etc even though it has a right date displying in the DB itself.

Any suggestions?
 
You can use several ways to format the date, I would however do what you want *inside* mysql!

I would not use a variable from PHP to set a date inside of mysql, if that time/date is now().

Then, I would rather fix the fieldtype to timestamp or use now().

When formatting the date, you can use several functions, depending a bit on your version of mysql.

This is not really an php matter, so I think you should read this:

I urge you to read it all, and test it all, as then you will have a completely new window to look out of!
Many things will then be easy for you to make..

Things like "days to your birthday", "active users", "last seen", etc. It's all very simple to make, if you just know what you have to toy around with.

Both mysql.com and php.net have great resources in theire manuals. I most of the time prefer them before googling, but even so, you can use google to search through them :)

Good luck! (I dont think you'll need it, though!)

Olav Alexander Mjelde
Admin & Webmaster
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top