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




Bookmarks