469,326 Members | 1,588 Online
Bytes | Developer Community
New Post

Home Posts Topics Members FAQ

Post your question to a community of 469,326 developers. It's quick & easy.

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("SUBMIT") <> "") and(Request("SUBMIT") = "SUBMIT") ) Then
set rstinsert = server.CreateObject("ADODB.Recordset")

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

lastName=request("lastName")
middleName=request("middleName")
firstName=request("firstName")
if Request("rbpostname")= "Jr" then
postName=Jr
else
postName=Sr
end if
dateBorn=request("dateBorn")
dateExpired=request("dateExpired")
cemetaryDetails=request("cemetaryDetails")
VisitationDetails=request("VisitationDetails")
ServicesDetails=request("ServicesDetails")

if Request.Form("current") = true then
rstinsert("current") = "Yes"
else
rstinsert("current") = "No"
end if
' dateExpired=Now()
sqlinsert = "insert into visitations(salutation,lastName,middleName,firstNa me,postName,dateBorn,dateExpired,cemetaryDetails,V isitationDetails,ServicesDetails,current) values('" & request("radiobutton") & "','" & lastName & "' , '" & middleName & "', '" & firstName & "','" & request("rbpostname") & "','" & dateBorn & "','" & dateExpired & "','" & cemetaryDetails & "' ,'" & VisitationDetails & "','" & ServicesDetails & "', '" & current & "')"
' dbCon.Execute SQL_query
rstinsert.Open sqlinsert,dbCon,3,2
' response.Write("added")
Response.Redirect("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.
Oct 25 '07 #1
4 1387
shweta123
692 Expert 512MB
Hi,

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

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





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("SUBMIT") <> "") and(Request("SUBMIT") = "SUBMIT") ) Then
set rstinsert = server.CreateObject("ADODB.Recordset")

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

lastName=request("lastName")
middleName=request("middleName")
firstName=request("firstName")
if Request("rbpostname")= "Jr" then
postName=Jr
else
postName=Sr
end if
dateBorn=request("dateBorn")
dateExpired=request("dateExpired")
cemetaryDetails=request("cemetaryDetails")
VisitationDetails=request("VisitationDetails")
ServicesDetails=request("ServicesDetails")

if Request.Form("current") = true then
rstinsert("current") = "Yes"
else
rstinsert("current") = "No"
end if
' dateExpired=Now()
sqlinsert = "insert into visitations(salutation,lastName,middleName,firstNa me,postName,dateBorn,dateExpired,cemetaryDetails,V isitationDetails,ServicesDetails,current) values('" & request("radiobutton") & "','" & lastName & "' , '" & middleName & "', '" & firstName & "','" & request("rbpostname") & "','" & dateBorn & "','" & dateExpired & "','" & cemetaryDetails & "' ,'" & VisitationDetails & "','" & ServicesDetails & "', '" & current & "')"
' dbCon.Execute SQL_query
rstinsert.Open sqlinsert,dbCon,3,2
' response.Write("added")
Response.Redirect("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.
Oct 25 '07 #2
radcaesar
759 Expert 512MB
Whats ur Database, Is it Access ?
Oct 25 '07 #3
markrawlingson
346 Expert 100+
Couple problems here...

Expand|Select|Wrap|Line Numbers
  1. if Request.Form("current") = true then
  2. rstinsert("current") = "Yes"
  3. else
  4. rstinsert("current") = "No"
  5. end if
  6.  
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.

Expand|Select|Wrap|Line Numbers
  1. if Request.Form("current") = "on" then
  2. rstinsert("current") = -1
  3. else
  4. rstinsert("current") = 0
  5. end if
  6.  
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.

Expand|Select|Wrap|Line Numbers
  1. if Request.Form("current") = "on" then
  2. rstinsert("current") = -1
  3. end if
  4.  
That last bit is, of course, merely a suggestion though :)

Sincerely,
Mark
Oct 25 '07 #4
yes.i am using ms-access.can u pl tell me how to store yes/no field in database
Oct 29 '07 #5

Post your reply

Sign in to post your reply or Sign up for a free account.

Similar topics

3 posts views Thread by Raju V.K | last post: by
2 posts views Thread by Nhat Yen | last post: by
20 posts views Thread by Patrick Guio | last post: by
10 posts views Thread by Anton.Nikiforov | last post: by
5 posts views Thread by John N. | last post: by
reply views Thread by zhoujie | last post: by
reply views Thread by suresh191 | last post: by
reply views Thread by mdpf | last post: by
reply views Thread by listenups61195 | last post: by
By using this site, you agree to our Privacy Policy and Terms of Use.