473,406 Members | 2,404 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,406 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******
Expand|Select|Wrap|Line Numbers
  1. <%
  2.  
  3.         If( (Request("SUBMIT") <> "") and(Request("SUBMIT") = "SUBMIT") ) Then
  4.                 set rstinsert = server.CreateObject("ADODB.Recordset")
  5.  
  6.         if Request("radiobutton") = "Ms" then
  7.                 salutation = Ms
  8.         elseif Request("radiobutton") = "Mrs" then
  9.                 salutation = Mrs
  10.         else
  11.                 salutation = Mr
  12.            end if 
  13.  
  14.          lastName=request("lastName")
  15.          middleName=request("middleName")
  16.          firstName=request("firstName")
  17.          if Request("rbpostname")= "Jr" then
  18.            postName=Jr
  19.          else
  20.            postName=Sr
  21.          end if         
  22.          dateBorn=request("dateBorn")
  23.          dateExpired=request("dateExpired")
  24.          cemetaryDetails=request("cemetaryDetails")
  25.          VisitationDetails=request("VisitationDetails")
  26.          ServicesDetails=request("ServicesDetails")
  27.  
  28.          if Request.Form("current") = true then
  29.               rstinsert("current") = "Yes"
  30.          else
  31.              rstinsert("current") = "No"
  32.          end if
  33.         ' dateExpired=Now()
  34.          sqlinsert = "insert into visitations(salutation,lastName,middleName,firstName,postName,dateBorn,dateExpired,cemetaryDetails,VisitationDetails,ServicesDetails,current) values('" & request("radiobutton") & "','" & lastName & "' , '" & middleName & "', '" & firstName & "','" & request("rbpostname") & "','" & dateBorn & "','" & dateExpired & "','" & cemetaryDetails & "' ,'" & VisitationDetails & "','" & ServicesDetails & "', '" & current & "')"   
  35.         ' dbCon.Execute SQL_query
  36.          rstinsert.Open sqlinsert,dbCon,3,2
  37. '         response.Write("added")
  38.          Response.Redirect("visitations.asp?valid=true")
  39.          'response.write(sqlinsert)
  40.          end if
  41.    %>
  42.  
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
5 1115
JamieHowarth0
533 Expert 512MB
Hi gudipati,

This question should be in the ASP Forum, not the Articles section (Articles is only to be used for sharing information and not for asking questions).

medicineworker
Oct 25 '07 #2
jhardman
3,406 Expert 2GB
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
These lines

Expand|Select|Wrap|Line Numbers
  1.         ' dateExpired=Now()
  2.          sqlinsert = "insert into visitations(salutation,lastName,middleName,firstName,postName,dateBorn,dateExpired,cemetaryDetails,VisitationDetails,ServicesDetails,current) values('" & request("radiobutton") & "','" & lastName & "' , '" & middleName & "', '" & firstName & "','" & request("rbpostname") & "','" & dateBorn & "','" & dateExpired & "','" & cemetaryDetails & "' ,'" & VisitationDetails & "','" & ServicesDetails & "', '" & current & "')"   
don't match with these lines. It looks like maybe "rstinsert" is left over from a previous attempt or some other code snippet. This should work:
Expand|Select|Wrap|Line Numbers
  1. dim current
  2.          if Request.Form("current") = true then
  3.               current = "Yes"
  4.          else
  5.              current = "No"
  6.          end if
[/quote]
Oct 25 '07 #3
hi i tried what u said.still i did't get.
Oct 26 '07 #4
jhardman
3,406 Expert 2GB
hi i tried what u said.still i did't get.
which line gives you the error?
Oct 26 '07 #5
markrawlingson
346 Expert 100+
if Request.Form("current") = true then
Checkboxes do not return a boolean value. They return, by default, a value of "on" if they are checked, and do not return a value if they are not checked. If you set the value attribute of a checkbox, the checkbox will return that value if it is checked, but it still will not return a value if it is not checked.

With that said, you're also setting your checkbox to a value of "" - so you can never tell whether it was checked or not. Since a checkbox that is not checked will not be returned in the Request.Form object - Request.Form("current") will have a value of "" if it is not checked. If the checkbox IS checked, since you are setting its value="" it will also have a value of "" if it IS checked.

Next...

rstinsert("current") = "Yes"
If you are using access, which i'm assuming you are because you referred to it as a yes/no field, this value should be -1 for yes, and 0 for no.

Here is the proper code.

First your checkbox.
Expand|Select|Wrap|Line Numbers
  1. <input type="checkbox" name="current" id="current"/>
  2.  
And the ASP to get the result of the "current" checkbox.

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.  
And finally a suggestion...

In your access database, if you set the default value of a yes/no field to 0 - when a new record is inserted, the value of this field will be false/0/no etc, unless you specifically tell it that it is true/1/yes etc when you are inserting a new record. This make programming yes/no boxes much easier, and your coding much leaner.

Expand|Select|Wrap|Line Numbers
  1. If Request.Form("current") = "on" then
  2.    rstinsert("current") = -1
  3. End If
  4.  
In other words, if the checkbox is checked - set the yes/no field to yes. If it not checked, don't do anything because the default value of the yes/no field is automatically no, and we don't have to worry about telling it that it is supposed to be false if the checkbox is not checked.

The last part, of course, is merely a suggestion.
Oct 26 '07 #6

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...
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
4
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
BarryA
by: BarryA | last post by:
What are the essential steps and strategies outlined in the Data Structures and Algorithms (DSA) roadmap for aspiring data scientists? How can individuals effectively utilize this roadmap to progress...
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
marktang
by: marktang | last post by:
ONU (Optical Network Unit) is one of the key components for providing high-speed Internet services. Its primary function is to act as an endpoint device located at the user's premises. However,...
0
Oralloy
by: Oralloy | last post by:
Hello folks, I am unable to find appropriate documentation on the type promotion of bit-fields when using the generalised comparison operator "<=>". The problem is that using the GNU compilers,...
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
agi2029
by: agi2029 | last post by:
Let's talk about the concept of autonomous AI software engineers and no-code agents. These AIs are designed to manage the entire lifecycle of a software development project—planning, coding, testing,...

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.