473,396 Members | 1,804 Online
Bytes | Software Development & Data Engineering Community
Post Job

Home Posts Topics Members FAQ

Join Bytes to post your question to a community of 473,396 software developers and data experts.

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 1511
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

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

Similar topics

3
by: Raju V.K | last post by:
I am developing a PHP-mysql database. It is noted that when the browser window is refreshed the data is inserted again in the database. unfortunately there is no unique keys that I can use to...
0
by: Bernhard Schmidt | last post by:
------=_NextPart_000_0030_01C34C51.B8F4D1A0 Content-Type: text/plain; charset="iso-8859-1" Content-Transfer-Encoding: quoted-printable hi dear mysql list members =20 i have setup a mysql...
2
by: Nhat Yen | last post by:
Hi everyone, I tried to upload my database to my web host. Nevertheless as they do not give me enough permission to perform some DTS thus I have to generate script to do it myself. The problem...
20
by: Patrick Guio | last post by:
Dear all, I have some problem with insertion operator together with namespace. I have a header file foo.h containing declaration of classes, typedefs and insertion operators for the typedefs in...
10
by: Anton.Nikiforov | last post by:
Dear all, i have a problem with insertion data and running post insert trigger on it. Preambula: there is a table named raw: ipsrc | cidr ipdst | cidr bytes | bigint time | timestamp...
5
by: John N. | last post by:
Hi All, Here I have a linked list each containing a char and is double linked. Then I have a pointer to an item in that list which is the current insertion point. In this funtion, the user...
1
by: Sam | last post by:
Hi all Is it possible to remove/disable automatic new row insertion feature in datagrid control(last row with * on the left)? I'm implementing a datagrid table which consists of 4 columns and...
0
by: polocar | last post by:
Hi, I have noticed a strange behaviour of CurrencyManager objects in C# (I use Visual Studio 2005 Professional Edition). Suppose that you have a SQL Server database with 2 tables called "Cities"...
1
by: teo | last post by:
Hallo, I'm performing a mass insertion from a text file to a db table with AdoNet commands, like this: myCommand.CommandText = "BULK INSERT ..." from a Win form no problem
5
by: gudipati | last post by:
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....
0
by: Charles Arthur | last post by:
How do i turn on java script on a villaon, callus and itel keypad mobile phone
0
by: emmanuelkatto | last post by:
Hi All, I am Emmanuel katto from Uganda. I want to ask what challenges you've faced while migrating a website to cloud. Please let me know. Thanks! Emmanuel
1
by: nemocccc | last post by:
hello, everyone, I want to develop a software for my android phone for daily needs, any suggestions?
1
by: Sonnysonu | last post by:
This is the data of csv file 1 2 3 1 2 3 1 2 3 1 2 3 2 3 2 3 3 the lengths should be different i have to store the data by column-wise with in the specific length. suppose the i have to...
0
by: Hystou | last post by:
There are some requirements for setting up RAID: 1. The motherboard and BIOS support RAID configuration. 2. The motherboard has 2 or more available SATA protocol SSD/HDD slots (including MSATA, M.2...
0
by: Hystou | last post by:
Most computers default to English, but sometimes we require a different language, especially when relocating. Forgot to request a specific language before your computer shipped? No problem! You can...
0
jinu1996
by: jinu1996 | last post by:
In today's digital age, having a compelling online presence is paramount for businesses aiming to thrive in a competitive landscape. At the heart of this digital strategy lies an intricately woven...
0
by: Hystou | last post by:
Overview: Windows 11 and 10 have less user interface control over operating system update behaviour than previous versions of Windows. In Windows 11 and 10, there is no way to turn off the Windows...
0
tracyyun
by: tracyyun | last post by:
Dear forum friends, With the development of smart home technology, a variety of wireless communication protocols have appeared on the market, such as Zigbee, Z-Wave, Wi-Fi, Bluetooth, etc. Each...

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.