Skip to main content
Known Participant
March 27, 2009
Question

SQL Insert issues

  • March 27, 2009
  • 3 replies
  • 914 views
I have a simple insert that is not working what so ever.

Here is my code:

<form action="emails.cfm" method="post" >
<input name="emailAddress" type="text" id="email_address" />
<input name="firstName" type="text" id="firstname" />
<input name="lastName" type="text" id="lastname" />
<input name="addEmail" type="submit" id="addEmail" value="Add Email">
</form>


emails.cfm code:

<cfquery name="addEmail" datasource="karavel">
Insert Into Emails (email_address,firstname,lastname)
Values('#Trim(FORM.emailAddress)#', '#Trim(FORM.firstName)#', '#Trim(FORM.lastName)#',)
</cfquery>




I keep getting an error saying that there is a syntax error in my insert into statement. Any ideas?

error msg:

Error Occurred While Processing Request
Error Executing Database Query.
[Macromedia][SequeLink JDBC Driver][ODBC Socket][Microsoft][ODBC Microsoft Access Driver] Syntax error in INSERT INTO statement.

The error occurred in C:\Websites\177371xx6\upgrade\emails.cfm: line 3

1 : <cfquery name="addEmail" datasource="karavel">
2 : Insert Into Emails (email_address,firstname,lastname)
3 : Values(#Trim(FORM.emailAddress)#, #Trim(FORM.firstName)#, #Trim(FORM.lastName)#,)
4 : </cfquery>

SQLSTATE 42000
SQL Insert Into Emails (email_address,firstname,lastname) Values(hh, hh, hh,)
VENDORERRORCODE -3502
DATASOURCE karavel
Resources:
This topic has been closed for replies.

3 replies

Inspiring
March 27, 2009
One of the more important things experience teaches is the minor things are usually the culprits ... so you learn to look for those first ;-)

You might consider placing the comma first, so it is harder to overlook. It is more "readable" IMO, and also makes it easier to comment out columns columns when debugging.

INSERT INTO Table
(
email_address
, firstname
, lastname
)
...
Known Participant
March 27, 2009
Hey thanks! It was that stupid comma at the end. I had a feeling it was something minor, just not experienced enough to spot those kind of details
Inspiring
March 27, 2009
> SQL Insert Into Emails (email_address,firstname,lastname) Values(hh, hh, hh, )

1. String values like "hh" need to be enclosed in single quotes. Though you may already have corrected that problem in emails.cfm.
2. There is an extra comma after the last value: Values(hh, hh, hh, <!--- extra comma here --->)