SitePoint Sponsor

User Tag List

Results 1 to 4 of 4
  1. #1
    SitePoint Addict
    Join Date
    Oct 2003
    Location
    Tenerife, Spain / UK
    Posts
    329
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)

    Error Object Required (Boolean Problem I think)

    Hi I'm trying to write a Generic Form to Database Parser, basically this script should take the values of Form fields and write them into a Database Table with correspondingly named fields.

    EG: The value contained in <input type="text" name="Email" > would be written to the database field "Email"

    I ran into difficulty when I tried to differntiate between Numeric and Non-Numeric Data as non-numeric data values must appear in quotes in a SQL Statment whereas Numeric Data should not be placed in Quotes. So I'm testing my form values to see if they are numeric, so I can build my SQL Statement Accordingly.

    The problem is I'm getting this error message

    Error Type: Microsoft VBScript runtime (0x800A01A8) Object required Line 84.

    This line reads:
    If IsNumeric(StrName) is True Then


    Here's the code.
    <%
    Dim StrName
    Dim StrSQL, StrTable, x , intcount

    StrTable = "Services"
    StrSQL = "INSERT INTO " & strtable & " ("

    x=1
    IntCount = Request.Querystring.count
    For each StrName in Request.Querystring
    If StrName = "Submit" Then

    'Skip Submit Button
    Else
    'Build our SQL Statement, by looping thru the name value pairs

    'If we have reached the last name value pair
    'we will not add a comma to the end of the SQL string
    'that we are building
    If x= IntCount Then
    StrSQL= StrSQL & strName
    Else
    StrSQL= StrSQL & strName &", "
    End If
    x= x+1
    End If
    Next
    StrSQL= StrSQL &") VALUES ("
    x=1
    IntCount = Request.Querystring.count
    For each StrName in Request.Querystring

    Response.write(strName & "Numeric: "&IsNumeric(Request.QueryString(strName))&"<br />")
    If StrName = "Submit" Then
    'Skip Submit Button as we don't want its value in the database
    Else
    'Build our SQL Statement, by looping thru the name value pairs

    If x= IntCount Then
    'We have rached the last StrName in the Collection so we don't add a comma
    'to the SQL string
    If IsNumeric(strName) is true Then
    'Numeric values are not enclosed in quotes
    StrSQL= StrSQL & Request.QueryString(strName)
    Else
    'String Values must be enclosed in quotes
    StrSQL= StrSQL &"'" & Request.QueryString(strName) &"'"
    End If
    Else
    If IsNumeric(StrName) is true Then
    'Numeric values are not enclosed in quotes
    StrSQL= StrSQL & Request.QueryString(strName) &", "
    Else
    'String Values must be enclosed in quotes
    StrSQL= StrSQL &"'"& Request.QueryString(strName) &"', "
    End If
    End If
    x= x+1
    End If
    Next
    StrSQL = StrSQL & ")"
    Response.write(StrSQL)

    'ObjConn.Execute StrSQL

    %>

    Yes apologies for the ugly nested If statement, I need to work on that.
    But as you see line 67:

    Response.write(strName & "Numeric: "&IsNumeric(Request.QueryString(strName))&"<br />")

    Outputs the True/False value of each field, I have both Numeric and Non Numeric Data, I just can't seem to pull of the isNumeric(StrName) function as a condition for an If Statement.

    Any help here would be great.

    Thanks

    David

  2. #2
    SitePoint Member
    Join Date
    Aug 2005
    Posts
    15
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    Sorry I didn't read all of the code you write but instead of writing
    Code:
    If IsNumeric(StrName) is True Then
    you can simply write
    Code:
    If IsNumeric(StrName) Then
    or
    Code:
    If IsNumeric(StrName)=TRUE Then
    But I prefer the first one.
    And, if your algorithm is true then the code must work...

  3. #3
    SitePoint Addict
    Join Date
    Oct 2003
    Location
    Tenerife, Spain / UK
    Posts
    329
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)

    Question

    I tried the other two variants

    Code:
    If IsNumeric(StrName) Then
    
    If IsNumeric(StrName)=TRUE Then
    And the script runs with no vbscript errors

    However, it fails to determine which values taken by StrName are actually numeric. Sample Output below.

    clientid Numeric: True
    domain Numeric: False
    Submit Numeric: False
    service Numeric: False
    renewaldate Numeric: False
    INSERT INTO Services (clientid, domain, service, renewaldate, ) VALUES ('1', 'forbes.com', 'Domain Registration', '12/11/2004', )

    Note that ClientID when tested on line 67
    Code:
    Response.write(strName & "Numeric:  "&IsNumeric(Request.QueryString(strName))&"<br />")
    Returns true, but when tested on line 84 to determine if the value should be enclosed in quotes, using the alternate code variation:
    Code:
    87: If IsNumeric(StrName) Then
    The value 1 is still enclosed in quotes!

  4. #4
    SitePoint Addict
    Join Date
    Oct 2003
    Location
    Tenerife, Spain / UK
    Posts
    329
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)

    Thumbs up Man I'm a duffer!

    Doh! I'm such a Duffer!

    There's nothing wrong with my code, I'm just testing the wrong value.

    StrName is the field name,

    Request.Querystring(StrName) is the value!

    On line 67 I correctly test the Value:

    IsNumeric(Request.QueryString(strName) but on line 84 I test the Field name

    IsNumeric(StrName)

    The field names will never be numeric as they are labels!!!

    Well at least I got it sussed.. Thanks for your help.


Bookmarks

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •