Skip to main content
Known Participant
July 19, 2006
Question

Syntax error in UPDATE statement

  • July 19, 2006
  • 7 replies
  • 654 views
I know this is a very basic process but for the life of me, I can't figure out what is wrong wide my code. I have created a simple Access database named Jobs. There are four fields within this database, the Primary Key, "Position" "Needs" and "Necessary". (I originally had them as Position, Description and Requirements but was told my issue might be that those were reserved words.)
Anyway, here is the code to the update form cfm page:
<cfquery name= "JobPost"
datasource="kpstool_accesscf_jobs">
SELECT * FROM jobs WHERE JobID = #Form.position#
</cfquery>
<cfoutput query= "JobPost">
<form action="Updatepage.cfm" Method="Post" name="Form" id="Form">
<p>
<table width="473" border="1">
<tr>
<td width="84">Position:</td>
<td width="373">
<input type="text" name="Position" value="#Position#"></td>
</tr>
<tr>
<td>Needs:</td>
<td><input type="text" name="Needs" value="#Needs#"></td>
</tr>
<tr>
<td>Necessary:</td>
<td><input type="text" name="Necessary" value="#Necessary#"></td>
</tr>
<tr>
<td colspan="2"><input name="submit" type="submit" value="Update Information"></td>
</tr>
</table>
<p><br>
<br>
</form>
</cfoutput>

Now here is the code for the update page cfm:

<cfquery name="JobPost"
datasource= "kpstool_accesscf_jobs">
UPDATE Jobs
SET Position = '#Form.Position#',
Needs = '#Form.Needs#',
Necessary = '#Form.Necessary#'
WHERE Position = President
</cfquery>
<cfoutput>
You have updated the information for added #Form.Position#
#Form.Needs#
to the Job Listing database
</cfoutput>

Lastly, here's the error I am getting:
Error Executing Database Query.

Syntax error in UPDATE statement.

The error occurred in D:\Hosting\kpstool\updatepage.cfm: line 134
132 : SET Position = '#Form.Position#',
133 : Needs = '#Form.Needs#',
134 : Necessary = '#Form.Necessary#'
135 : WHERE Position = President
136 : </cfquery>
SQL UPDATE Jobs SET Position = 'President', Needs = 'Tell people what to do', Necessary = 'Must yell' WHERE Position = President
DATASOURCE kpstool_accesscf_jobs
VENDORERRORCODE 3092
SQLSTATE  

ANY help would be GREAT!

Dave
This topic has been closed for replies.

7 replies

Known Participant
July 19, 2006
THAT WORKED!!!!

Thanks everyone for their quick replies and especially to you paross1.

Dave
Known Participant
July 19, 2006
I also tried retyping the info for the Necessary field and still go the same:


Syntax error in UPDATE statement.

The error occurred in D:\Hosting\kpstool\updatepage.cfm: line 134
132 : SET Position = '#Form.Position#',
133 : Needs = '#Form.Needs#',
134 : Necessary = '#Form.Necessary#'
135 : WHERE Position = 'President'
136 : </cfquery>
SQL UPDATE Jobs SET Position = 'President', Needs = 'Talk', Necessary = 'Yell' WHERE Position = 'President'
DATASOURCE kpstool_accesscf_jobs
VENDORERRORCODE 3092
SQLSTATE  
Participating Frequently
July 19, 2006
I know that you are using Access, but I researched reserved words in SQL Server Books Online, and position is on the list of ODBC Reserved Keywords. You might try enclosing that word in brackets [ ]:

UPDATE Jobs
SET [Position] = 'President',
Needs = 'Talk',
Necessary = 'Yell'
WHERE [Position] = 'President'

Phil
Known Participant
July 19, 2006
On line 135, Position is a text field. I am choosing the President listing in the field and trying to update it. Anyway, I tried the single quote and still got the same error:

Error Executing Database Query.

Syntax error in UPDATE statement.

The error occurred in D:\Hosting\kpstool\updatepage.cfm: line 134
132 : SET Position = '#Form.Position#',
133 : Needs = '#Form.Needs#',
134 : Necessary = '#Form.Necessary#'
135 : WHERE Position = 'President'
136 : </cfquery>
July 19, 2006
You may have some unprintable character on line 134. Try retypiing it.
Inspiring
July 19, 2006
SQL syntax uses single quotes, not double, for strings.
> 135 : WHERE Position = 'President'


Dave Blake wrote:
> Well I tried adding the quotes but no luck:
> Error Executing Database Query.
>
> Syntax error in UPDATE statement.
>
> The error occurred in D:\Hosting\kpstool\updatepage.cfm: line 134
> 132 : SET Position = '#Form.Position#',
> 133 : Needs = '#Form.Needs#',
> 134 : Necessary = '#Form.Necessary#'
> 135 : WHERE Position = "President"
> 136 : </cfquery>
>
Known Participant
July 19, 2006
Well I tried adding the quotes but no luck:
Error Executing Database Query.

Syntax error in UPDATE statement.

The error occurred in D:\Hosting\kpstool\updatepage.cfm: line 134
132 : SET Position = '#Form.Position#',
133 : Needs = '#Form.Needs#',
134 : Necessary = '#Form.Necessary#'
135 : WHERE Position = "President"
136 : </cfquery>
Inspiring
July 19, 2006
You need quotes around the word President.