Solved

When i submit if check box is not checked the page will error out  other wise it works.

Posted on 2006-11-17
21
259 Views
Last Modified: 2012-08-14
here is the code.

<%


Dim connectstr
dim strSQL

set oConn = Server.CreateObject("ADODB.Connection")
connectstr = "filedsn=" & Server.MapPath("_dsn") & "\access_svatba.dsn"

oConn.Open connectstr


strSQL = "insert into attendees (firstname, lastname, email, phonenumber, streetaddress, " & _
                         "city, state, zip, groupplans) values ('" & cleanstr(Request.Form("firstname")) & "','" & _
                         cleanstr(request.form("lastname")) & "','" & cleanstr(Request.Form("email")) & "','" & _
                         cleanstr(Request.Form("phonenumber")) & "','" & cleanstr(Request.Form("streetaddress")) & "','" & _
                         cleanstr(Request.Form("city")) & "','" & Request.Form("state") & "','"
                         
strSQL = strSQL & cleanstr(Request.Form("zip")) & "'," & request.form("groupplans") & ")"

oConn.execute(strSQL)

set oConn = Nothing
Response.Redirect "../mailing.asp?act=add"

function CleanStr(str)

      CleanStr = replace(str,"'","’")
      
end function

%>
0
Comment
Question by:valve79
  • 9
  • 7
  • 4
  • +1
21 Comments
 
LVL 43

Expert Comment

by:TimCottee
ID: 17965750
Hi valve79,

Which value relates to the checkbox? Groupplans perhaps?

Tim Cottee
0
 

Author Comment

by:valve79
ID: 17965762
ah sorry -
its the groupplans
0
 
LVL 35

Expert Comment

by:YZlat
ID: 17965816
try

strSQL = strSQL & cleanstr(Request.Form("zip")) & "'," & CBool(request.form("groupplans")) & ")"
0
 

Author Comment

by:valve79
ID: 17965846
now its opposite it errors out when i do have it checked the following error is

Microsoft VBScript runtime error '800a000d'

Type mismatch: 'CBool'

/adddata.asp, line 19
0
 
LVL 35

Expert Comment

by:YZlat
ID: 17965857
then try

if request.form("groupplans")="" then
      qroup=false
else
   group=true
end if
strSQL = strSQL & cleanstr(Request.Form("zip")) & "'," & group & ")"
0
 
LVL 9

Expert Comment

by:deathtospam
ID: 17965859
What kind of database are you connecting to (SQL Server, Access, etc), and what is the datatype of the [groupplans] column in the [attendees] table?  Are NULL values allowed?


-= DeathToSpam =-


0
 
LVL 35

Expert Comment

by:YZlat
ID: 17965861
or even better:

then try

if request.form("groupplans")="" then
      qroup=false
elseif request.form("groupplans")="on" then
   group=true
end if
strSQL = strSQL & cleanstr(Request.Form("zip")) & "'," & group & ")"
0
 
LVL 35

Expert Comment

by:YZlat
ID: 17965875
when you sumit the form and the checkbox is unchecked, request.form("groupplans") returns an empty string to the page. An empty string cannot be inserted into the boolean field
0
 

Author Comment

by:valve79
ID: 17965955
Im using access the data type for groupplans is yes/no

the last code still didnt work
0
 
LVL 35

Expert Comment

by:YZlat
ID: 17965994
this should work

if request.form("groupplans")="" then
      qroup=false
elseif request.form("groupplans")="on" then
   group=true
end if
strSQL = strSQL & cleanstr(Request.Form("zip")) & "'," & group & ")"


or try

if request.form("groupplans")="" then
      qroup="No"
elseif request.form("groupplans")="on" then
   group="Yes"
end if
strSQL = strSQL & cleanstr(Request.Form("zip")) & "'," & group & ")"

or

if request.form("groupplans")="" then
      qroup="No"
elseif request.form("groupplans")="on" then
   group="Yes"
end if
strSQL = strSQL & cleanstr(Request.Form("zip")) & "','" & group & "')"

0
Is Your Active Directory as Secure as You Think?

More than 75% of all records are compromised because of the loss or theft of a privileged credential. Experts have been exploring Active Directory infrastructure to identify key threats and establish best practices for keeping data safe. Attend this month’s webinar to learn more.

 

Author Comment

by:valve79
ID: 17966075
I tried all three still gives me error when the box is not checked

Microsoft OLE DB Provider for ODBC Drivers error '80040e07'

[Microsoft][ODBC Microsoft Access Driver] Data type mismatch in criteria expression.

/adddata.asp, line 30
0
 
LVL 35

Expert Comment

by:YZlat
ID: 17966189
what about this?

if request.form("groupplans")="" then
      qroup="No"
elseif request.form("groupplans")="on" then
   group="Yes"
end if
strSQL = strSQL & cleanstr(Request.Form("zip")) & "','" & group & "')"
0
 
LVL 35

Expert Comment

by:YZlat
ID: 17966197
could you print out your sql to the screen and then post it here?

if request.form("groupplans")="" then
      qroup="No"
elseif request.form("groupplans")="on" then
   group="Yes"
end if
strSQL = strSQL & cleanstr(Request.Form("zip")) & "','" & group & "')"

Response.write strSQL
Response.End
0
 
LVL 9

Expert Comment

by:deathtospam
ID: 17966204
valve79 --

Can you please post the HTML checkbox code that you're using for the [groupplans] variables?


-= DeathToSpam =-
0
 
LVL 35

Expert Comment

by:YZlat
ID: 17966238
actually even if db field is Yes/No, in your sql statement you should use True or False:

if request.form("groupplans")="" then
      qroup=false
elseif request.form("groupplans")="on" then
   group=true
end if
strSQL = strSQL & cleanstr(Request.Form("zip")) & "'," & group & ")"

Response.write strSQL
REsponse.end
0
 

Author Comment

by:valve79
ID: 17966245
                 <tr>
                        <td width=95 align=right class='form'>Group plans:</td>      
                        <td width=5>&nbsp;</td>
                        <td widht=200><input type="checkbox" name="groupplans" class='form'></td>
                  </tr>      
0
 

Author Comment

by:valve79
ID: 17966349
unchecked gives me error -

insert into attendees (firstname, lastname, email, phonenumber, streetaddress, city, state, zip, groupplans) values ('test','test','valve79@gmail.com','7033891144','6903 Dillon Ave','mclean','VA','22101',)

checked -

insert into attendees (firstname, lastname, email, phonenumber, streetaddress, city, state, zip, groupplans) values ('test','test','valve79@gmail.com','7033891144','6903 Dillon Ave','mclean','VA','22101',True)
0
 
LVL 9

Expert Comment

by:deathtospam
ID: 17966515
Try making the following changes to your code:

<%
'// [sGroupplansValue] is True if the checkbox is checkbox; otherwise, it is False.
sGroupplansValue = "No":  If (Trim(Request("groupplans")) <> "") Then sGroupplansValue = "Yes"

set oConn = Server.CreateObject("ADODB.Connection")
connectstr = "filedsn=" & Server.MapPath("_dsn") & "\access_svatba.dsn"
oConn.Open connectstr

'<snipped code>

'// Notice how we changed the INSERT statement to reference [sGroupplansValue]
strSQL = "insert into attendees (firstname, lastname, email, phonenumber, streetaddress, " & _
      "city, state, zip, groupplans) values ('" & cleanstr(Request.Form("firstname")) & "','" & _
      cleanstr(request.form("lastname")) & "','" & cleanstr(Request.Form("email")) & "','" & _
      cleanstr(Request.Form("phonenumber")) & "','" & cleanstr(Request.Form("streetaddress")) & "','" & _
      cleanstr(Request.Form("city")) & "','" & Request.Form("state") & "','" & _
      cleanstr(Request.Form("zip")) & "','" & Trim(sGroupplansValue) & "')"

'<snipped code>
%>


-= DeathToSpam =-
0
 
LVL 35

Expert Comment

by:YZlat
ID: 17967286
this:

if request.form("groupplans")="" then
      qroup=false
     strSQL = strSQL & cleanstr(Request.Form("zip")) & "'," & group & ")"
else
strSQL = strSQL & cleanstr(Request.Form("zip")) & "'," & request.form("groupplans") & ")"


end if


will give you

insert into attendees (firstname, lastname, email, phonenumber, streetaddress, city, state, zip, groupplans) values ('test','test','valve79@gmail.com','7033891144','6903 Dillon Ave','mclean','VA','22101', False)

when unchecked

0
 

Author Comment

by:valve79
ID: 17982363
Well non of the codes worked, I did figure out that access is looking for either 1 or 0 thats as far I got
0
 
LVL 9

Accepted Solution

by:
deathtospam earned 125 total points
ID: 17987573
Here's a revised version of my original suggestion, to use 0/1 instead:

=======================================
<%
'// [iGroupplansValue] is 1 if the checkbox is checked; otherwise, it is 0.
iGroupplansValue = 0:  If (Trim(Request("groupplans")) <> "") Then iGroupplansValue = 1

set oConn = Server.CreateObject("ADODB.Connection")
connectstr = "filedsn=" & Server.MapPath("_dsn") & "\access_svatba.dsn"
oConn.Open connectstr

'<snipped code>

'// Notice how we changed the INSERT statement to reference [iGroupplansValue ]
strSQL = "insert into attendees (firstname, lastname, email, phonenumber, streetaddress, " & _
     "city, state, zip, groupplans) values ('" & cleanstr(Request.Form("firstname")) & "','" & _
     cleanstr(request.form("lastname")) & "','" & cleanstr(Request.Form("email")) & "','" & _
     cleanstr(Request.Form("phonenumber")) & "','" & cleanstr(Request.Form("streetaddress")) & "','" & _
     cleanstr(Request.Form("city")) & "','" & Request.Form("state") & "','" & _
     cleanstr(Request.Form("zip")) & "'," & iGroupplansValue & ")"

'<snipped code>
%>
=======================================

-= DeathToSpam =-
0

Featured Post

Is Your Active Directory as Secure as You Think?

More than 75% of all records are compromised because of the loss or theft of a privileged credential. Experts have been exploring Active Directory infrastructure to identify key threats and establish best practices for keeping data safe. Attend this month’s webinar to learn more.

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

Suggested Solutions

Title # Comments Views Activity
How to solve this equation 3 52
Classic ASP - SQL Server connection problem 5 61
Response.Flush in Classic ASP causing TIME_WAIT ports 9 85
XML Parsing Classic ASP 5 50
Hello, all! I just recently started using Microsoft's IIS 7.5 within Windows 7, as I just downloaded and installed the 90 day trial of Windows 7. (Got to love Microsoft for allowing 90 days) The main reason for downloading and testing Windows 7 is t…
I was asked about the differences between classic ASP and ASP.NET, so let me put them down here, for reference: Let's make the introductions... Classic ASP was launched by Microsoft in 1998 and dynamically generate web pages upon user interact…
Many functions in Excel can make decisions. The most simple of these is the IF function: it returns a value depending on whether a condition you describe is true or false. Once you get the hang of using the IF function, you will find it easier to us…
Both in life and business – not all partnerships are created equal. As the demand for cloud services increases, so do the number of self-proclaimed cloud partners. Asking the right questions up front in the partnership, will enable both parties …

895 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question

Need Help in Real-Time?

Connect with top rated Experts

15 Experts available now in Live!

Get 1:1 Help Now