I'm trying to simply have a user input some information through a form, then use an INSERT statement to write it to my database.
I know that my connections are all working properly, because if I hard-code all the values into the insert statement, then it works. However, when I replace the static text with variables, I get errors.
Any help is appreciated!
Here is my code:
<html>
<head>
<title>ColdFusion Hello World!</title>
</head>
<body>
<cfform action="First Page.cfm" method="post">
First Name: <cfinput type="text" name="firstname" required="yes"><br />
Last Name: <cfinput type="text" name="lastname" required="yes"><br />
Message: <cfinput type="text" name="message" size="80" required="yes"><br /><br />
<input type="submit" value="Submit" name="Submit">
</cfform>
<br /><br />
<cfif isDefined('form.firstname') AND isDefined('form.lastname')>
<cfoutput>
Thank You!
</cfoutput>
<cfquery name="selectQuery" datasource="Playground">
SELECT * FROM Names
</cfquery>
<cfset variable.message=form.message>
<cfset variable.rownum=selectQuery.currentrow+1>
<cfquery name="insertQuery" datasource="Playground">
INSERT INTO Names
VALUES (#variable.rownum#, #DateFormat(Now(), "mm/dd/yy")#, #form.firstname#, #form.lastname#, #variable.message#)
</cfquery>
</cfif>
</body>
</html>
UPDATE!!!
If I have spaces in my message variable, then the error changes
Here is the error I'm getting with no spaces:
Error Executing Database Query.
[Macromedia][SQLServer JDBC Driver][SQLServer]Invalid column name 'FirstTest'.
The error occurred in C:\ColdFusion9\wwwroot\CFWork\First Page.cfm: line 28
26 : <cfquery name="insertQuery" datasource="Playground">
27 : INSERT INTO Names
28 : VALUES (#variable.rownum#, #DateFormat(Now(), "mm/dd/yy")#, #form.firstname#, #form.lastname#, #variable.message#)
29 : </cfquery>
30 : </cfif>
VENDORERRORCODE 207
SQLSTATE 42S22
SQL INSERT INTO Names VALUES (2, 02/14/10, FirstTest, LastTest, TestTest)
DATASOURCE Playground
Here is the error with spaces in the message variable:
Error Executing Database Query.
[Macromedia][SQLServer JDBC Driver][SQLServer]Incorrect syntax near 'blah'.
The error occurred in C:\ColdFusion9\wwwroot\CFWork\First Page.cfm: line 28
26 : <cfquery name="insertQuery" datasource="Playground">
27 : INSERT INTO Names
28 : VALUES (#variable.rownum#, #DateFormat(Now(), "mm/dd/yy")#, #form.firstname#, #form.lastname#, #variable.message#)
29 : </cfquery>
30 : </cfif>
VENDORERRORCODE 102
SQLSTATE HY000
SQL INSERT INTO Names VALUES (2, 02/14/10, first, last, blah blah)
DATASOURCE Playground
This post has been edited by xTorvos: 14 February 2010 - 02:53 AM

New Topic/Question
Reply



MultiQuote






|