Hello and welcome to our community! Is this your first visit?
Register
Enjoy an ad free experience by logging in. Not a member yet? Register.
Results 1 to 15 of 15
  1. #1
    Regular Coder
    Join Date
    Nov 2005
    Posts
    750
    Thanks
    138
    Thanked 1 Time in 1 Post

    Two issues with addRecords.asp file

    Hello

    I have an addRecords.asp file which, when the completed form is submitted, fills in a vacant row in the MS Access database except for the address field (which is set as a 'text' field in my database). I don't get any error messages, only that that address column is left blank. Is there a way of correcting that?

    The other problem is that when I get the form up on screen, leave all the fields blank, and then press [Enter] on my keyboard, I get the following error:

    Microsoft VBScript runtime error '800a000d'

    Type mismatch: 'CDBL'

    /addRecords.asp, line 122
    Line 122 is this:
    Code:
    my_wolfID = CDBL( Request.Form("wolfID") )
    In my database, wolfID is a number and it is not required (screenshot).

    What might be responsible for that error, please?
    Attached Thumbnails Attached Thumbnails Two issues with addRecords.asp file-wolfid.jpg  

  • #2
    Supreme Master coder! Old Pedant's Avatar
    Join Date
    Feb 2009
    Posts
    27,191
    Thanks
    80
    Thanked 4,562 Times in 4,526 Posts
    *THINK* about it for just a moment.

    If you do *NOT* fill in the form field wolfID and then submit the <form>, *WHAT IS THE VALUE of Request("wolfID")???

    HINT: *ALL* <form> fields have a value! No <form> field is *EVER* NULL.

    Heck, test it yourself:
    Code:
        Response.Write Request("wolfID")
    What gets written to the browser???

    DO NOT GUESS! Figure it out.
    An optimist sees the glass as half full.
    A pessimist sees the glass as half empty.
    A realist drinks it no matter how much there is.

  • #3
    Supreme Master coder! Old Pedant's Avatar
    Join Date
    Feb 2009
    Posts
    27,191
    Thanks
    80
    Thanked 4,562 Times in 4,526 Posts
    The answer is quite simple: If the user does not enter a value for a given <form> field, then then the value defaults to "". That is, it defaults to an empty string: A string with a length of ZERO.

    Yes, it is *STILL* a string. A string with a length of zero is *NOT* the same thing as a NULL value.

    Okay, so now what do you think happens when you try to convert a blank string to a number?

    That is, when you attempt to do
    Code:
         n = CDBL( "" )
    ???

    ANSWER: YOU GET A TYPE MISMATCH! Because there is *NO POSSIBLE NUMERIC VALUE* that is the same as the blank string!!!

    Finally, if you would simply EXPERIMENT just a little, instead of just throwing code at the wall and hoping it will stick, you could figure this out for yourself.

    For example:
    Code:
    s = Request("wolfID")
    If IsNumeric( s ) Then
        Response.Write "s is a number, specifically " & CDBL(s) & "<hr/>"
    Else
        Response.Write "s is not a number, so I cannot use CDBL(s) in any meaningful way.<hr/>"
    End If
    An optimist sees the glass as half full.
    A pessimist sees the glass as half empty.
    A realist drinks it no matter how much there is.

  • #4
    Supreme Master coder! Old Pedant's Avatar
    Join Date
    Feb 2009
    Posts
    27,191
    Thanks
    80
    Thanked 4,562 Times in 4,526 Posts
    Quote Originally Posted by SteveH View Post
    I have an addRecords.asp file which, when the completed form is submitted, fills in a vacant row in the MS Access database except for the address field (which is set as a 'text' field in my database). I don't get any error messages, only that that address column is left blank. Is there a way of correcting that?
    Of course there is. By figuring out where the error in your coding is.

    Given the code you showed us, my best guess would be that you omitted a semicolon at character position 37 on line number 433 in the file "bananaPudding.asp".

    No? Well, that's the best I can guess from the code you showed.
    An optimist sees the glass as half full.
    A pessimist sees the glass as half empty.
    A realist drinks it no matter how much there is.

  • #5
    Regular Coder
    Join Date
    Nov 2005
    Posts
    750
    Thanks
    138
    Thanked 1 Time in 1 Post
    Hello OP

    Thanks for your reply.

    OK, I will attempt to tackle one issue at a time. Firstly, the missing address field. There are no semi-colons:

    I have the declarations, then the 'connect to the database', and then this:

    Code:
    Dim conn, rs, my_fullName, my_wolfID, my_telNo, my_address, my_email, my_description, my_received, my_action, my_dispatched
    
    ' set varaible values from request.form
    
    my_fullName = Replace( Request.Form("fullName"), "'", "''" )
    my_wolfID = CDBL( Request.Form("wolfID") )
    my_telNo = CDBL( Request.Form("telNo") )
    my_address = Replace( Request.Form("address"), "'", "''" )
    my_email = Replace( Request.Form("email"), "'", "''" )
    my_description = Replace( Request.Form("description"), "'", "''" )
    my_received = CDATE( Request.Form("received") )
    my_action = Replace( Request.Form("action"), "'", "''" )
    my_dispatched = Replace( Request.Form("dispatched"), "'", "''" )
    
    'build insert statement
    
    sSQL="INSERT INTO tblWolf " &_
     "(fullName, wolfID, telNo, address, email, description, received, [action], dispatched)" &_
     " VALUES ('" & my_fullName & "', " & my_wolfID & ", " & my_telNo & ", '" & address & "', '" & my_email & "', '" & my_description & "', #" & my_received & "#, '" & my_action & "', '" & my_dispatched & "')"
    
    ' insert record
    connection.Execute sSQL
    
    Response.write "<div class='center'><p class='font'>The record has been added.</p></div>"
    As you will see, 'address' is treated in the same way as 'email', 'description', etc which do appear after I have added a new record, so I can't understand why address doesn't appear in its column after I have added a new record.

    Address will typically be something like: 2 The Carters Liverpool L5 4SE or 2, The Carters, Liverpool L5 4SE.

    Thanks for looking at it.

  • #6
    Supreme Master coder! Old Pedant's Avatar
    Join Date
    Feb 2009
    Posts
    27,191
    Thanks
    80
    Thanked 4,562 Times in 4,526 Posts
    And how many times have I suggested that you DEBUG DEBUG DEBUG DEBUG DEBUG?

    Code:
    sSQL="INSERT INTO tblWolf " &_
     "(fullName, wolfID, telNo, address, email, description, received, [action], dispatched)" &_
     " VALUES ('" & my_fullName & "', " & my_wolfID & ", " & my_telNo & ", '" & address & "', '" & my_email & "', '" & my_description & "', #" & my_received & "#, '" & my_action & "', '" & my_dispatched & "')"
    
    Response.Write "<hr/>DEBUG SQL: " & sSQL & "<hr/>"
    
    ' insert record
    connection.Execute sSQL
    WHAT DOES THAT DEBUG show you?

    I guarantee that it shows you have a BLANK value for address.

    WHY can I guarantee that???
    An optimist sees the glass as half full.
    A pessimist sees the glass as half empty.
    A realist drinks it no matter how much there is.

  • #7
    Supreme Master coder! Old Pedant's Avatar
    Join Date
    Feb 2009
    Posts
    27,191
    Thanks
    80
    Thanked 4,562 Times in 4,526 Posts
    I can guarantee that because your code does this:
    Code:
    my_address = Replace( Request.Form("address"), "'", "''" )
    but then your code creates the sSQL string using this:
    Code:
    " VALUES ('" & my_fullName & "', " & my_wolfID & ", " & my_telNo & ", '" & address & "', '" & my_email ...
    Why would you expect address and my_address to contain the same values?
    An optimist sees the glass as half full.
    A pessimist sees the glass as half empty.
    A realist drinks it no matter how much there is.

  • Users who have thanked Old Pedant for this post:

    SteveH (11-18-2013)

  • #8
    Regular Coder
    Join Date
    Nov 2005
    Posts
    750
    Thanks
    138
    Thanked 1 Time in 1 Post
    Hello OP

    I have started to use
    Code:
    Response.Write "<hr/>DEBUG SQL: " & sSQL & "<hr/>"
    more and more.

    When I add it, I get:

    DEBUG SQL: INSERT INTO tblWolf (fullName, wolfID, telNo, address, email, description, received, [action], dispatched) VALUES ('', 0, 0, '', '', '', #12:00:00 AM#, '', '')

    and yes, it is '0'.

    Steve

  • #9
    Regular Coder
    Join Date
    Nov 2005
    Posts
    750
    Thanks
    138
    Thanked 1 Time in 1 Post
    Hello OP

    Code:
    '" & address & "'
    I don't know how I could possibly have missed that. I have now changed it to
    Code:
    '" & my_address & "'
    and, needless to say, the script is now adding the address field to the record.

    I can't thank you enough!

    Steve

  • #10
    Supreme Master coder! Old Pedant's Avatar
    Join Date
    Feb 2009
    Posts
    27,191
    Thanks
    80
    Thanked 4,562 Times in 4,526 Posts
    Note that simply being more careful would help a lot.

    But when you aren't careful, debugging is vital. (Heck, it's vital even when you are careful...it is *SO* easy to make a simple little typo.)

    "If you don't know how to debug, then you can't program." Said to me maybe 40 years ago, and it is still just as true today.
    An optimist sees the glass as half full.
    A pessimist sees the glass as half empty.
    A realist drinks it no matter how much there is.

  • #11
    Regular Coder
    Join Date
    Nov 2005
    Posts
    750
    Thanks
    138
    Thanked 1 Time in 1 Post
    Hello OP

    Yes, I remember you showed me:


    Code:
    Response.Write "<hr/>DEBUG SQL:<br/>" & sSQL & "<hr/>" & vbNewLine
    and the alternative:

    Code:
    On Error Resume Next
        connection.Execute sSQL (for example)
        If Err.Number > 0 Then
            Response.Write "<hr/>ERROR from query: " & Err.Description & "<br/>SQL:<br/>" & sSQL & "<hr/>" 
            Response.End
        End If
    On Error GoTo 0
    Thanks for that.

    40 years? Wow! You must have seen more code than there are grains of sand on the beach!

    Steve

  • #12
    Supreme Master coder! Old Pedant's Avatar
    Join Date
    Feb 2009
    Posts
    27,191
    Thanks
    80
    Thanked 4,562 Times in 4,526 Posts
    Wrote my first program in 1963, doing my roommate's homework for him. <grin/>

    But then didn't really start programming until 1969. Things had changed a lot in those 6 years.
    An optimist sees the glass as half full.
    A pessimist sees the glass as half empty.
    A realist drinks it no matter how much there is.

  • #13
    Regular Coder
    Join Date
    Nov 2005
    Posts
    750
    Thanks
    138
    Thanked 1 Time in 1 Post
    How long did it take you before you felt you had mastered ASP? Was it dedicated study?

  • #14
    Supreme Master coder! Old Pedant's Avatar
    Join Date
    Feb 2009
    Posts
    27,191
    Thanks
    80
    Thanked 4,562 Times in 4,526 Posts
    "Mastered"...hmmm...I guess I could say that I could do anything I wanted with ASP within 18 months of first encountering it. Oh, I learned other things after that time, but pretty much insignificant things, in comparison.

    But understand that ASP was just a sideline for me at that time (1999-2000). Long story.
    An optimist sees the glass as half full.
    A pessimist sees the glass as half empty.
    A realist drinks it no matter how much there is.

  • #15
    Regular Coder
    Join Date
    Nov 2005
    Posts
    750
    Thanks
    138
    Thanked 1 Time in 1 Post
    Well, I wish you all the best - you have been nothing but helpful to me.

    Steve


  •  

    Posting Permissions

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