insertion into database

Collapse
X
 
  • Time
  • Show
Clear All
new posts
  • gudipati
    New Member
    • Oct 2007
    • 21

    insertion into database

    hi i have one checkbox in the form if i check that it should be check in the database field.(in database yes/no field for ckeckbox).what is my problem is every thing is stored except checkbox field.
    can u pl correct me?
    this is my check box.*******
    <input name="current" type="checkbox" id="current" value="">

    this is insertion code******

    <%

    If( (Request("SUBMI T") <> "") and(Request("SU BMIT") = "SUBMIT") ) Then
    set rstinsert = server.CreateOb ject("ADODB.Rec ordset")

    if Request("radiob utton") = "Ms" then
    salutation = Ms
    elseif Request("radiob utton") = "Mrs" then
    salutation = Mrs
    else
    salutation = Mr
    end if

    lastName=reques t("lastName")
    middleName=requ est("middleName ")
    firstName=reque st("firstName" )
    if Request("rbpost name")= "Jr" then
    postName=Jr
    else
    postName=Sr
    end if
    dateBorn=reques t("dateBorn")
    dateExpired=req uest("dateExpir ed")
    cemetaryDetails =request("cemet aryDetails")
    VisitationDetai ls=request("Vis itationDetails" )
    ServicesDetails =request("Servi cesDetails")

    if Request.Form("c urrent") = true then
    rstinsert("curr ent") = "Yes"
    else
    rstinsert("curr ent") = "No"
    end if
    ' dateExpired=Now ()
    sqlinsert = "insert into visitations(sal utation,lastNam e,middleName,fi rstName,postNam e,dateBorn,date Expired,cemetar yDetails,Visita tionDetails,Ser vicesDetails,cu rrent) values('" & request("radiob utton") & "','" & lastName & "' , '" & middleName & "', '" & firstName & "','" & request("rbpost name") & "','" & dateBorn & "','" & dateExpired & "','" & cemetaryDetails & "' ,'" & VisitationDetai ls & "','" & ServicesDetails & "', '" & current & "')"
    ' dbCon.Execute SQL_query
    rstinsert.Open sqlinsert,dbCon ,3,2
    ' response.Write( "added")
    Response.Redire ct("visitations .asp?valid=true ")
    'response.write (sqlinsert)
    end if
    %>

    may be i have done mistake in sqlinsert stmt pl correct if u have any idea.currect is the database yes/no field.
  • shweta123
    Recognized Expert Contributor
    • Nov 2006
    • 692

    #2
    Hi,

    I think , you are not able to insert into the database because in the following code value of Request.Form("c urrent") may be empty or null.
    if Request.Form("c urrent") = true then
    rstinsert("curr ent") = "Yes"
    else
    rstinsert("curr ent") = "No"
    end if

    Please check that value using Response.write( Request.Form("c urrent")).





    Originally posted by gudipati
    hi i have one checkbox in the form if i check that it should be check in the database field.(in database yes/no field for ckeckbox).what is my problem is every thing is stored except checkbox field.
    can u pl correct me?
    this is my check box.*******
    <input name="current" type="checkbox" id="current" value="">

    this is insertion code******

    <%

    If( (Request("SUBMI T") <> "") and(Request("SU BMIT") = "SUBMIT") ) Then
    set rstinsert = server.CreateOb ject("ADODB.Rec ordset")

    if Request("radiob utton") = "Ms" then
    salutation = Ms
    elseif Request("radiob utton") = "Mrs" then
    salutation = Mrs
    else
    salutation = Mr
    end if

    lastName=reques t("lastName")
    middleName=requ est("middleName ")
    firstName=reque st("firstName" )
    if Request("rbpost name")= "Jr" then
    postName=Jr
    else
    postName=Sr
    end if
    dateBorn=reques t("dateBorn")
    dateExpired=req uest("dateExpir ed")
    cemetaryDetails =request("cemet aryDetails")
    VisitationDetai ls=request("Vis itationDetails" )
    ServicesDetails =request("Servi cesDetails")

    if Request.Form("c urrent") = true then
    rstinsert("curr ent") = "Yes"
    else
    rstinsert("curr ent") = "No"
    end if
    ' dateExpired=Now ()
    sqlinsert = "insert into visitations(sal utation,lastNam e,middleName,fi rstName,postNam e,dateBorn,date Expired,cemetar yDetails,Visita tionDetails,Ser vicesDetails,cu rrent) values('" & request("radiob utton") & "','" & lastName & "' , '" & middleName & "', '" & firstName & "','" & request("rbpost name") & "','" & dateBorn & "','" & dateExpired & "','" & cemetaryDetails & "' ,'" & VisitationDetai ls & "','" & ServicesDetails & "', '" & current & "')"
    ' dbCon.Execute SQL_query
    rstinsert.Open sqlinsert,dbCon ,3,2
    ' response.Write( "added")
    Response.Redire ct("visitations .asp?valid=true ")
    'response.write (sqlinsert)
    end if
    %>

    may be i have done mistake in sqlinsert stmt pl correct if u have any idea.currect is the database yes/no field.

    Comment

    • radcaesar
      Recognized Expert Contributor
      • Sep 2006
      • 759

      #3
      Whats ur Database, Is it Access ?

      Comment

      • markrawlingson
        Recognized Expert Contributor
        • Aug 2007
        • 346

        #4
        Couple problems here...

        [CODE=asp]
        if Request.Form("c urrent") = true then
        rstinsert("curr ent") = "Yes"
        else
        rstinsert("curr ent") = "No"
        end if
        [/CODE]

        First off, I find this to be a very common mistake/problem people run into - so I may write an article about it in the asp article forum...

        Anyway, checkboxes never return as a boolean true/false value. By default they return "on" (as a string) if they are checked, and they do no return anything if they are not checked. If you supply a value attribute to your checkbox, they will return that value if they are checked, but they will still never return a value if they are not checked. In fact, if a checkbox is not checked it will not even be a part of the request.form collection (because it returns no value).

        Second, database type is important when it comes to yes/no or bit data types. I'm assuming it's access since you referred to it as a yes/no field as I believe all other databases refer to boolean data fields as bit type. I believe that Access stores yes/no data type as -1 for yes and 0 for no - but I could be wrong about that - it's been a while since I've used an access database. My research seems to support this though... :P

        So with that said, check out the below code - it should by all means fix your issue if you are using an access database.

        [CODE=ASP]
        if Request.Form("c urrent") = "on" then
        rstinsert("curr ent") = -1
        else
        rstinsert("curr ent") = 0
        end if
        [/CODE]

        Further to this, for lean code purposes I usually have a default value set up in my database as false (or 0 in the case of access) for boolean type data, so that when a new record is added, unless I tell my database that the value of this field is true (or -1) then it will be inserted as false/0 - that way I don't have to specify in the code every single time that this field is false.

        [CODE=ASP]
        if Request.Form("c urrent") = "on" then
        rstinsert("curr ent") = -1
        end if
        [/CODE]

        That last bit is, of course, merely a suggestion though :)

        Sincerely,
        Mark

        Comment

        • gudipati
          New Member
          • Oct 2007
          • 21

          #5
          yes.i am using ms-access.can u pl tell me how to store yes/no field in database

          Comment

          Working...