• Status: Solved
  • Priority: Medium
  • Security: Public
  • Views: 3004
  • Last Modified:

CF ERROR MSG: The value "" cannot be converted to a number

Hi All,

I need help in trying to figure out why a random error seems to happen. I have built a continuing education search and registration application. People will search for their workshops and then click a button to go and register/pay for the workshops. This has been live for a few months and the error below has happend a few times. It does not happen each time. It just seems to happen sporadically. I cannot figure out why most of the registrations will work and a few will not.

I am lost at why this happens every now and then. I think it is with the "TotalFees" variable.

Any suggestions would be wonderful! Thanks

ERROR:
MESSAGE The value "" cannot be converted to a number


CODE (IN THE BODY IS "ERROR OCCURS HERE ---->")
<cflock scope="session" type="readonly" timeout="5">
<CFQUERY NAME="versions" DATASOURCE="ceworkshops" DBTYPE="ODBC">
SELECT ID,Session_Number,Title,WorkshopDate,WorkshopTime,Member_Earlybird,Member_Advanced_Fee,Non_Member_Earlybird,Non_Member_Advanced_Fee,
Member_Onsite_Fee,Non_Member_Onsite_Fee,Credits
FROM celisting
WHERE id IN (#session.classes#)
ORDER BY session_number
</cfquery>
</cflock>

<p>Final Schedule For <cfoutput>#attributes.fname# #attributes.lname#</cfoutput></p>

<cfset totalFees = "0">

<cfoutput query="versions" group="workshopdate">
<p><span class="textbold">#workshopdate#</span></p>


<table>
<tr>
      <td>ID</td>
      <td>Title</td>
      <td>Credits</td>
      <td>Time</td>
      <td>Fee</td>
      
</tr>
<cfoutput>
<tr>
      <td>#session_number#</td>
      <td>#title#</td>
      <td>#credits#</td>
      <td>#workshoptime#</td>

      <cflock scope="session" type="readonly" timeout="5">

      <!---shows early bird rate--->
      <cfif #session.validMember# EQ "YES">
            <td>#DollarFormat(member_earlybird)#</td>
ERROR OCCURS HERE ---->            <cfset totalFees = #totalFees# + #member_earlybird#>
            
      <cfelse>
            <td>#DollarFormat(non_member_earlybird)#</td>
OR ERROR OCCURS HERE ---->            <cfset totalFees = #totalFees# + #non_member_earlybird#>
      </cfif>
      

      </cflock>
      
</tr>
</cfoutput>

</table>
</cfoutput>

<table width="100%">
<cfoutput>
<tr>
      <td>Total to be Charged to Credit Card:</td>
      <td>#DollarFormat(totalFees)#</td>
      <input type="hidden" name="totalfees" value="#totalfees#">
</tr>
</cfoutput>
</table>
0
Mamea
Asked:
Mamea
  • 3
  • 2
  • 2
  • +1
1 Solution
 
damtrojanCommented:
Without knowing the output of your query it's hard to trouble shoot but I do have a couple of suggestions.

1.  I would lose the double quotes on your <cfset totalFees = "0">.  Numbers can stand alone like variables.  "" usually indicate strings.

2. Make sure your users sessions are not timing out which might give them an empty query which might not break dollarformat, but will break your add script.  Use an "isnumeric(non_member_earlybird)" to test or a "versions.recordcount" to make sure you have at least 1 value.

Hope this helps a bit.
0
 
dgrafxCommented:
General Suggestions:
Remove the lock around your query
Remove # from coldfusion statements
In your query you have the line:
WHERE id IN (#session.classes#)
This will throw an error if and when the value session.classes is null or not a number.

As far as your error goes - Do this:
<td>
<cfif session.validMember is "yes">
      <cfif isNumeric(member_earlybird)>
      #DollarFormat(member_earlybird)#
      <cfset totalFees = totalFees + member_earlybird>
      </cfif>
<cfelse>
      <cfif isNumeric(non_member_earlybird)>
      #DollarFormat(non_member_earlybird)#
                 <cfset totalFees = totalFees + non_member_earlybird>
      </cfif>
</cfif>
</td>
0
 
aseusaincCommented:
You could also try <cfset totalFees = #evaluate(#totalFees# + #non_member_earlybird#)#>
0
Become an Android App Developer

Ready to kick start your career in 2018? Learn how to build an Android app in January’s Course of the Month and open the door to new opportunities.

 
MameaAuthor Commented:
Hi All,

Thank you all for your suggestions. A few things.

1. I do know that the session variables have NOT expired because they are showing up in the error report.

2. I originally had <cfset totalFees = 0> but changed it to <cfset totalFees = "0"> after I received the same error as above with the <cfset totalFees = 0>.

3. I orignally had the following code below and it threw the same error as above so that is when i added the # signs around the totalFees and member_earlybird/non_member_earlybird.

4. the member_earlybird/non_member_earlybird is NOT a number is the dbase. it is a text field. basically what happens is in session.classes (this is a list of numbers). that list of numbers is compared to the ce listing table and if a match occurs then the appropriate workshop information is displayed. basically the text fields are 450.00 or 90.00 or 270.00. that is the format and that is why i addition will work for the most part on the cfset totalFees.

i can remove the cflock around the qry however the other suggestion except for  aseusainc are for things that I have already done and change to the programming I showed above.

Any other ideas????


Thanks


<cflock scope="session" type="readonly" timeout="5">

<cfif #session.validMember# EQ "YES">
<td>#DollarFormat(member_earlybird)#</td>
<cfset totalFees = totalFees + member_earlybird>

<cfelse>

<td>#DollarFormat(non_member_earlybird)#</td>
<cfset totalFees = totalFees + non_member_earlybird>

</cfif>
</cflock>
      
0
 
aseusaincCommented:
After your further decription, that some of these values are being pulled from a database, it seems to me that you may have a NULL value where something is expected.  I would check through your db for data consistancy.

ERROR:
MESSAGE The value "" cannot be converted to a number

Kind of looks like a text field that CF is trying to typecast to a number is empty.
0
 
aseusaincCommented:
If you really want a catch all (without using a try/catch), you could use something like BEFORE your calculation:

<cfif #isnumeric(member_earlybird)# IS FALSE>
  <cfset #member_earlybird# = 0>
</cfif>
0
 
dgrafxCommented:
Mamea
I should have elaborated ...
The first part of my answer had nothing to do with your error, but were simply statements meant to improve your coding practices.
Locking this query and also in your most recent post you lock an cfif block. This is not needed. It is not a situation where you need a lock. You should remove you locks for code like this. You can read about how and why to use lock in your cf docs.
Also, using #'s inside ColdFusion statements is inefficient and screams "newbie". It is not how the language was designed. #'s are meant for when you need to give a vars value to the browser (to the user), Not to the ColdFusion server. Remove them from your code.
Also <cfset totalFees = 0> vs <cfset totalFees = "0"> There is no difference - but you should use <cfset totalFees = 0>

Now about your error ...
Did you try this?
<td>
<cfif session.validMember is "yes">
     <cfif isNumeric(member_earlybird)>
     #DollarFormat(member_earlybird)#
     <cfset totalFees = totalFees + member_earlybird>
     </cfif>
<cfelse>
     <cfif isNumeric(non_member_earlybird)>
     #DollarFormat(non_member_earlybird)#
                 <cfset totalFees = totalFees + non_member_earlybird>
     </cfif>
</cfif>
</td>
I don't see a reason why it wouldn't work.
You have an error that says basicly that "" cannot be converted to a number - which is logical.
So if you then say "only try to add this if it is a number" - then this is logical also.
You do it by saying cfif isNumeric(member_earlybird)

good luck ...


0
 
MameaAuthor Commented:
Hi aseusainc,

You nailed it on the head! Thank you! It ended up that 1 workshop out of 60 was missing those member_earlybird rates. All of the other workshops had the rate. I was too busy looking at the code and not the raw data. I have put in coding to fix that issue and now it works great! Thank you for you insight into looking into the database. :-)
0

Featured Post

Free Tool: Port Scanner

Check which ports are open to the outside world. Helps make sure that your firewall rules are working as intended.

One of a set of tools we are providing to everyone as a way of saying thank you for being a part of the community.

  • 3
  • 2
  • 2
  • +1
Tackle projects and never again get stuck behind a technical roadblock.
Join Now