Solved

problem with query

Posted on 2006-06-15
12
189 Views
Last Modified: 2013-12-24
hi have a little problem with this one could any one help?



 The value "UPDATE manufacturers SET name = '" cannot be converted to a number



            <cfif FORM.image IS "">
                  <cfset sql = "UPDATE manufacturers SET name = '" + #FORM.name# + "', contactName = '" + #FORM.contactName# + "', address = '" + #HTMLCodeFormat(FORM.address)# + "', postCode = '" + #FORM.postCode# + "', tel = '" + #FORM.tel# + "', fax = '" + #FORM.fax# + "', email = '" + #FORM.email# + "', website = '" + #FORM.website# + "', description = '" + #FORM.description# + "' WHERE manId = '" + #FORM.manId#  + "'">
            

            <cfelse>                  
                  another query here
            </cfif>
            <cfquery name="updateManufacturer" datasource="#dbSource#" username="#dbUsername#" password="#dbPassword#">
                  #sql#
            </cfquery>
            <cfset success = TRUE>
            <cfelse>
            <cfoutput> Please Reduce you input</cfoutput>
      </cfif>
      
0
Comment
Question by:pigmentarts
12 Comments
 
LVL 9

Expert Comment

by:73Spyder
ID: 16914176
First off.  I would write the query this way .  Much easier to read and trouble shoot.   I think the error is with the phone or fax number.  What are the data types for these feilds?  and are you padding hyphens in the form.  ie..   212-555-1212   Or just a number  2125551212

<cfif FORM.image IS "">
    <cfquery name="updateManufacturer" datasource="#dbSource#" username="#dbUsername#" password="#dbPassword#">
    UPDATE manufacturers
    SET name = '#FORM.name#',
    contactName = '#FORM.contactName#',
    address = '#HTMLCodeFormat(FORM.address)#',
    postCode = '#FORM.postCode#',
    tel = '#FORM.tel#',
    fax = '#FORM.fax#',
    email = '#FORM.email#',
    website = '#FORM.website#',
    description = '#FORM.description#'
    WHERE manId = '#FORM.manId#'
    </cfquery>
  <cfelse>              
    <cfquery name="updateManufacturer" datasource="#dbSource#" username="#dbUsername#" password="#dbPassword#">
    another query here
    </cfquery>      
</cfif>

<cfset success = TRUE>
<cfelse>
<cfoutput> Please Reduce you input</cfoutput>
</cfif>
0
 
LVL 9

Accepted Solution

by:
73Spyder earned 400 total points
ID: 16914189
Follow up.  I would also use the <cfqueryparam> tag in the query instead of each value inside of '' s
0
 
LVL 7

Assisted Solution

by:ExpertAdmin
ExpertAdmin earned 100 total points
ID: 16915295
I think the problem is that you are using the + to concatenate and CF tries to add the values together. You should use "&" Instead:

<cfset sql = "UPDATE manufacturers SET name = '" & #FORM.name# & ...


Just for the record though, I completely agree with 73Spyder...I see no advantage to building a string as opposed to just making it a CFQuery tag.

M@
0
PRTG Network Monitor: Intuitive Network Monitoring

Network Monitoring is essential to ensure that computer systems and network devices are running. Use PRTG to monitor LANs, servers, websites, applications and devices, bandwidth, virtual environments, remote systems, IoT, and many more. PRTG is easy to set up & use.

 
LVL 25

Expert Comment

by:dgrafx
ID: 16917284
not posting for points as these guys have your answer but I wanted to point out that:
since you are setting "sql" as a coldfusion var, the + sign is not going to concatenate, but tries to add.
you may have this confused with a query you've seen where you create a sql server (or whatever db) var like
sql = "UPDATE manufacturers SET name = '" + #FORM.name# + et cetera ...
coldfusion and sql server have different syntax for this type of thing
0
 
LVL 12

Author Comment

by:pigmentarts
ID: 16918271
the reason i am trying to put it in a string first is becuase the sql statment can be one or another so i dont want it set ie:

<cfif FORM.image IS "">
a sql string
<else>
a sql string
</cfif>

query with the the string here

i see what you are staying, i will try with the & and get back to you guys. thanks for your help!
0
 
LVL 12

Author Comment

by:pigmentarts
ID: 16918623
ok thanks, i have this

UPDATE manufacturers SET name = '#FORM.name#', contactName = '#FORM.contactName#', address = '#HTMLCodeFormat(FORM.address)#', postCode = '#FORM.postCode#', tel = '#FORM.tel#', fax = '#FORM.fax#', email = '#FORM.email#', website = '#FORM.website#', description = '#FORM.description#' WHERE manId = '#FORM.manId#'

UPDATE manufacturers SET name = ''Vitra'', contactName = ''test'', address = ''<PRE>dsasfdsf</PRE>'', postCode = ''sdfsdafs'', tel = ''13231231321'', fax = ''32312321312'', email = ''sdfsadf@yahoo.com'', website = ''fsdfdsfs'', description = ''Vitra is one of Europe''s leading bathroom manufacturers and sells products in over 50 countries worldwide.'' WHERE manId = ''1''

i still get this error:  [Macromedia][SQLServer JDBC Driver][SQLServer]Line 1: Incorrect syntax near 'Vitra'.

0
 
LVL 9

Expert Comment

by:73Spyder
ID: 16919303
The issue you are now getting is dealing with quotation marks.

use this tag  #PreserveSingleQuotes(mystring)#   ie.

UPDATE manufacturers SET name = <cfqueryparam cfsqltype="cf_sql_varchar" value="#PreserveSingleQuotes(FORM.name)#">,
contactName = <cfqueryparam cfsqltype="cf_sql_varchar" value="#PreserveSingleQuotes(FORM.contactName)#">,
address = <cfqueryparam cfsqltype="cf_sql_varchar" value="#HTMLCodeFormat(FORM.address)#">,
postCode = <cfqueryparam cfsqltype="cf_sql_varchar" value="#PreserveSingleQuotes(FORM.postCode)#">,
tel = <cfqueryparam cfsqltype="cf_sql_varchar" value="#PreserveSingleQuotes(FORM.tel)#">,
fax = <cfqueryparam cfsqltype="cf_sql_varchar" value="#PreserveSingleQuotes(FORM.fax)#">,
email = <cfqueryparam cfsqltype="cf_sql_varchar" value="#PreserveSingleQuotes(FORM.email)#">,
website = <cfqueryparam cfsqltype="cf_sql_varchar" value="#PreserveSingleQuotes(FORM.website)#">,
description = <cfqueryparam cfsqltype="cf_sql_varchar" value="#PreserveSingleQuotes(FORM.description)#">
WHERE manId = <cfqueryparam cfsqltype="cf_sql_varchar" value="#PreserveSingleQuotes(FORM.manId)#">

Probably a little bit of over kill here, but try this out.
0
 
LVL 9

Expert Comment

by:73Spyder
ID: 16919309
If you can use it, the cfqueryparam is a much more robust way of passing variables to sql.
0
 
LVL 12

Author Comment

by:pigmentarts
ID: 16919365
could you give me or a link to how to use cfqueryparam as the example i am finding are not too good.
0
 
LVL 9

Expert Comment

by:73Spyder
ID: 16919382
0
 
LVL 9

Expert Comment

by:73Spyder
ID: 16919385
Here are list of the possible cfsqltype 's that you can bind the values to
    * CF_SQL_BIGINT
    * CF_SQL_BIT
    * CF_SQL_CHAR
    * CF_SQL_BLOB
    * CF_SQL_CLOB
    * CF_SQL_DATE
    * CF_SQL_DECIMAL
    * CF_SQL_DOUBLE
    * CF_SQL_FLOAT
    * CF_SQL_IDSTAMP
    * CF_SQL_INTEGER
    * CF_SQL_LONGVARCHAR
    * CF_SQL_MONEY
    * CF_SQL_MONEY4
    * CF_SQL_NUMERIC
    * CF_SQL_REAL
    * CF_SQL_REFCURSOR
    * CF_SQL_SMALLINT
    * CF_SQL_TIME
    * CF_SQL_TIMESTAMP
    * CF_SQL_TINYINT
    * CF_SQL_VARCHAR


0
 
LVL 12

Author Comment

by:pigmentarts
ID: 16919406
thank you
0

Featured Post

Announcing the Most Valuable Experts of 2016

MVEs are more concerned with the satisfaction of those they help than with the considerable points they can earn. They are the types of people you feel privileged to call colleagues. Join us in honoring this amazing group of Experts.

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

Suggested Solutions

Title # Comments Views Activity
OpenLDAP set password to expire 7 692
Use System DSN 6 88
Problem to get function 52 111
Create sub domain on windows dedicated server. 13 72
If you don't have the right permissions set for your WordPress location in IIS, you won't be able to perform automatic updates. Here's how to fix the problem.
When it comes to showing a 404 error page to your visitors, you do not want that generic page to show, and you especially do not want your hosting provider’s ad error page to show either. In this article, I will show you how to enable the custom 40…
Although Jacob Bernoulli (1654-1705) has been credited as the creator of "Binomial Distribution Table", Gottfried Leibniz (1646-1716) did his dissertation on the subject in 1666; Leibniz you may recall is the co-inventor of "Calculus" and beat Isaac…
I've attached the XLSM Excel spreadsheet I used in the video and also text files containing the macros used.

789 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question