meensi thanks for your quick response. Let me clear two things up I am using ColdFusion 9 (not sure if it matters) and also I had it using "cfelse" and clob because I created a form and than manually clicked the server behaviors---->insert record and matched each form field with the DB table entry. So Dreamweaver/Coldfusion built in code set that string of code up for me. But I have since gone back and re-written it to adhere to your advice but am now getting this error:
Error Executing Database Query. |
| [Macromedia][SequeLink JDBC Driver][ODBC Socket][QODBC] Expected lexical element not found: |
| |
The error occurred in C:\inetpub\wwwroot\CFIDE\testsite\registration_page.cfm: line 36
|
34 :
35 : <cfif IsDefined('form.zipcode') and len(form.zipcode) NEQ 0>
36 : <cfset strBillAddressPostalCode=form.zipcode/>
37 : </cfif>
38 : )
|
|
| VENDORERRORCODE | 11015 | | SQLSTATE | 42000 | | SQL | INSERT INTO Customer (Name, LastName, FullName, BillAddressAddr1, BillAddressAddr2, BillAddressCity, BillAddressState, BillAddressPostalCode) VALUES ( ) | | DATASOURCE | QBs |
|
this is my new code just the cf fuction (I didn't change the second DB entry line of code yet bc I didn't think it would matter so it will show still using the cfquerparm and cfelse for that section.):
<cfif IsDefined("FORM.username")>
<cfquery name="MM_search" datasource="Access">
SELECT Logininfo.Username FROM Logininfo WHERE Logininfo.Username=<cfqueryparam value="#FORM.username#" cfsqltype="cf_sql_clob" maxlength="50">
</cfquery>
<cfif MM_search.RecordCount GTE 1>
<cflocation url="taken.cfm?requsername=#FORM.username#" addtoken="no">
</cfif>
</cfif>
<cfset CurrentPage=GetFileFromPath(GetBaseTemplatePath())>
<cfif IsDefined("FORM.MM_InsertRecord") AND FORM.MM_InsertRecord EQ "customer">
<cfquery datasource="QBs">
INSERT INTO Customer (Name, LastName, FullName, BillAddressAddr1, BillAddressAddr2, BillAddressCity, BillAddressState, BillAddressPostalCode)
VALUES (<cfif IsDefined('form.firstname') and len(form.firstname) NEQ 0>
<cfset strName=form.firstname/>
</cfif>
<cfif IsDefined('form.lastname') and len(form.lastname) NEQ 0>
<cfset strLastName=form.lastname/>
</cfif>
<cfset FullName=strName &''& LastName/>
<cfif IsDefined('form.streetaddress') and len(form.streetaddress) NEQ 0>
<cfset strBillAddressAddr2=form.streetaddress/>
</cfif>
<cfif IsDefined('form.city') and len(form.city) NEQ 0>
<cfset strBillAddressCity=form.city/>
</cfif>
<cfif IsDefined('form.state') and len(form.state) NEQ 0>
<cfset strBillAddressState=form.state/>
</cfif>
<cfif IsDefined('form.zipcode') and len(form.zipcode) NEQ 0>
<cfset strBillAddressPostalCode=form.zipcode/>
</cfif>
)
</cfquery>
<cfquery datasource="Access">
INSERT INTO Logininfo (FirstName, LastName, Username, Password)
VALUES (<cfif IsDefined("FORM.firstname") AND #FORM.firstname# NEQ "">
<cfqueryparam value="#FORM.firstname#" cfsqltype="cf_sql_clob" maxlength="25">
<cfelse>
''
</cfif>
, <cfif IsDefined("FORM.lastname") AND #FORM.lastname# NEQ "">
<cfqueryparam value="#FORM.lastname#" cfsqltype="cf_sql_clob" maxlength="25">
<cfelse>
''
</cfif>
, <cfif IsDefined("FORM.username") AND #FORM.username# NEQ "">
<cfqueryparam value="#FORM.username#" cfsqltype="cf_sql_clob" maxlength="25">
<cfelse>
''
</cfif>
, <cfif IsDefined("FORM.password") AND #FORM.password# NEQ "">
<cfqueryparam value="#FORM.password#" cfsqltype="cf_sql_clob" maxlength="25">
<cfelse>
''
</cfif>
)
</cfquery>
<cflocation url="login.cfm">
</cfif>
thanks for your help and I apologize for my rookie mistakes in advance!!!
Hi,
In the first query, where is the comma to separate the values.??? Thats the problem I think.
This is how your code should be.
1. set the values in the variables.
2. use the varaibles inside your CFQUERYPARAM
<cfif IsDefined('form.firstname') and len(form.firstname) NEQ 0>
<cfset strName=form.firstname/>
</cfif>
<cfif IsDefined('form.lastname') and len(form.lastname) NEQ 0>
<cfset strLastName=form.lastname/>
</cfif>
<cfset FullName=strName &''& LastName/>
<cfif IsDefined('form.streetaddress') and len(form.streetaddress) NEQ 0>
<cfset strBillAddressAddr2=form.streetaddress/>
</cfif>
<cfif IsDefined('form.city') and len(form.city) NEQ 0>
<cfset strBillAddressCity=form.city/>
</cfif>
<cfif IsDefined('form.state') and len(form.state) NEQ 0>
<cfset strBillAddressState=form.state/>
</cfif>
<cfif IsDefined('form.zipcode') and len(form.zipcode) NEQ 0>
<cfset strBillAddressPostalCode=form.zipcode/>
</cfif>
Please fill the maxlength and cfsqltype accordingly, also in your first query, billaddressAddr1 is missing (check that also); In the query i have added.
<cfquery datasource="QBs">
INSERT INTO Customer (Name, LastName, FullName, BillAddressAddr1, BillAddressAddr2, BillAddressCity, BillAddressState, BillAddressPostalCode)
VALUES (
<cfqueryparam value="#strName#" cfsqltype="cf_sql_clob" maxlength="25"/>,
<cfqueryparam value="#strLastName#" cfsqltype="cf_sql_clob" maxlength="25"/>,
<cfqueryparam value="#FullName#" cfsqltype="cf_sql_clob" maxlength="25"/>,
<cfqueryparam value="#BillAddressAddr1#" cfsqltype="cf_sql_clob" maxlength="25"/>,
<cfqueryparam value="#strBillAddressAddr2#" cfsqltype="cf_sql_clob" maxlength="25"/>,
<cfqueryparam value="#strBillAddressCity#" cfsqltype="cf_sql_clob" maxlength="25"/>,
<cfqueryparam value="#strBillAddressState#" cfsqltype="cf_sql_clob" maxlength="25"/>,
<cfqueryparam value="#strBillAddressPostalCode#" cfsqltype="cf_sql_clob" maxlength="25"/>)
</cfquery>
I hope this will work..