Jump to content

Sql Error


Piyush

Recommended Posts

I made this query $rs = odbc_exec($con, "UPDATE Data SET lastlogin='" . date("D d F, Y") . "',active=0 WHERE id=" . $id . ";");the error wasWarning: odbc_exec() [function.odbc-exec]: SQL error: [Microsoft][ODBC Microsoft Access Driver] Data type mismatch in criteria expression., SQL state 22005 in SQLExecDirect in C:\Inetpub\wwwroot\php_new\out.php on line 6here is my databasehttp://rapidshare.com/files/295944268/Data.mdb.htmlPlease Hep me with this... thanks...

Link to comment
Share on other sites

What is the datatype for the column lastlogin?I'm guessing the format for date is "Wed 21 October, 2009" so I'm guessing the datatype should have been string-friendly :)

Link to comment
Share on other sites

What is the datatype for the column lastlogin?I'm guessing the format for date is "Wed 21 October, 2009" so I'm guessing the datatype should have been string-friendly :)
Hi Kameloh...the lastlogin is of Date/Time type..is my date in wrong format?
Link to comment
Share on other sites

Yes i think there was problem in my data type .. the date i was inserting was in wrong format i think....when i tried changing the data type to text it worked successfuly...thanks...

Link to comment
Share on other sites

For efficiency you should use VARCHAR(30) since the lastlogin date you're inserting is between 20-30 characters. If you plan on changing the format of the date to something longer you can increase the size of varchar :)

Link to comment
Share on other sites

Using a text field to hold a date may work, but it's not as good as storing the date using date/time or as an integer timestamp. If you store it as text, for example, you won't be able to sort by date. Instead of sorting by date it's going to sort the dates in alphabetic order, not in date order. It might be better to figure out what format you need to use to insert into a date/time field and just use that format, or convert your date to an integer timestamp and store that in an integer field. Either way will let you sort by date.

Link to comment
Share on other sites

Another neat tip is to create 2 columns for date:1 to store it as INT and then use date('m/d/y', the_date);2 to store it as VARCHAR with a stringThe only benefit of this is that you can sort by date efficiently AND display the date without using much server resources other than disk space :)

Link to comment
Share on other sites

Archived

This topic is now archived and is closed to further replies.

×
×
  • Create New...