johnbarrett
03/05/2022, 12:27 AM<cfquery name="Insert"> INSERT INTO users(first_name, last_name, date)
VALUE("#form.first_name#", "#form.last_name#", "#CreateODBCDate(Now())#");
</cfquery>
Daniel Mejia
03/05/2022, 1:13 AMDaniel Mejia
03/05/2022, 1:14 AMDaniel Mejia
03/05/2022, 1:15 AMjohnbarrett
03/05/2022, 2:11 AMdeactivateduser
03/05/2022, 2:17 AMjohnbarrett
03/05/2022, 2:36 AMdeactivateduser
03/05/2022, 2:38 AMdeactivateduser
03/05/2022, 2:40 AMdeactivateduser
03/05/2022, 2:45 AMjohnbarrett
03/05/2022, 2:55 AMageax
03/05/2022, 3:51 AMdatetime
or varchar
?ageax
03/05/2022, 3:52 AMvarchar
from here...johnbarrett
03/05/2022, 3:56 AMageax
03/05/2022, 3:57 AMCreateODBCDate()
because that results in inserting a string into the db table instead of a date object. That would cause the query to fail if the target was a "datetime" column. It only works now because its type "varchar". Well... kinda works, because it inserts a string that "sort of" looks like a date object, but isn't really "{d '2022-03-05'}ageax
03/05/2022, 3:58 AMjohnbarrett
03/05/2022, 4:00 AM#CreateODBCDate(Now())#
instead of "#CreateODBCDate(Now())#"
? Thanks so much for your help!ageax
03/05/2022, 4:01 AMageax
03/05/2022, 4:03 AMjohnbarrett
03/05/2022, 4:34 AMageax
03/05/2022, 4:46 AMageax
03/05/2022, 6:22 AMCreateODBCDate(Now())Btw, that will truncate the time, and just return a date "2022-03-05". If you want both date and time, just use
Now()
like someone mentioned on another threadAdam Cameron
SHOW CREATE TABLE
(or the equiv on your platform of choice).
• It is 2022. There is no need to use createOdbcDate
(or its ilk).
• Don't hard code data values - especially ones from user input - in your SQL statements. Pass them as parameters. The SQL statement should just hold SQL. Values should be passed as values.
• It doesn't look like you are using a framework, given you are referencing the form scope directly in code that does DB writes. Esp as a newbie, one should be using a framework.
• At the very least one ought to be following MVC practices for this sort of code, and it doesn't look to me like you are separating your concerns properly (again: form scope references when writing to a DB).
There's some keyword searching and research for you to do there 😉johnbarrett
03/07/2022, 1:25 AMDavid Buck
03/07/2022, 2:57 PMPatrick S
03/07/2022, 3:48 PM