Skip to main content
Inspiring
February 11, 2009
Answered

Inserting a record, not working. Please help

  • February 11, 2009
  • 2 replies
  • 645 views
Hello;
I am stumped. I am trying to get this code to insert a new record, but when it goes through the code, it loses the record and doesn't insert it to the db. What am I missing? I can't figure it out.

My code:

<cfif isDefined("Form.newEdit_OK")>

<cfif isDefined("Form.RecordID")>
here is my query if it is updating and existing record
<cfelse>
<cfquery datasource="#APPLICATION.dataSource#" dbtype="ODBC">
INSERT INTO news
(title, newsDate, htmlList)
VALUES (<cfqueryparam cfsqltype="cf_sql_varchar" value="#form.title#">,
<cfqueryparam cfsqltype="cf_sql_date" value="#form.newsDate#">,
<cfqueryparam cfsqltype="cf_sql_longvarchar" value="#form.body#">)
</cfquery>
<cflocation url="news_RecordView.cfm">
</cfif>

What did I miss? I can't figure it out.

CFmonger
This topic has been closed for replies.
Correct answer Dan_Bracuk
I troubleshoot if/else problems like this:

<cfif something>
true
<cfelse>
false
<cfdump something>
</cfif>

2 replies

Dan_BracukCorrect answer
Inspiring
February 11, 2009
I troubleshoot if/else problems like this:

<cfif something>
true
<cfelse>
false
<cfdump something>
</cfif>

CFmongerAuthor
Inspiring
February 11, 2009
I used ths:
<cfdump var="#title#">

Did I write this correctly or go after the proper variable?
It just posted the title on a blank page. The title was from the form I am posting with. So it seems to be getting the variables to this point, it is something in my insert. Right?

Thanks for the help.
Inspiring
February 11, 2009
what type of form field is RecordID?
if it is a text/hidden field - it will ALWAYS be defined in the form.
hence the <cfelse> part of your code will never execute...

Azadi Saryev
Sabai-dee.com
http://www.sabai-dee.com/
CFmongerAuthor
Inspiring
February 11, 2009
this is the way my form is set up:

<form action="Action.cfm" method="post" name="news" id="news" onsubmit="saveIt()">
<input type="hidden" name="FieldList" value="#FormFieldList#">
<cfif isDefined("URL.RecordID")>
<input type="hidden" name="RecordID" value="#URL.RecordID#">
<input type="hidden" name="ID" value="#URL.RecordID#">
</cfif>
All my form fields are here
</form>

It should work.