Welcome to Experts Exchange

Add your voice to the tech community where 5M+ people, just like you, are talking about what matters.

  • Help others & share knowledge
  • Earn cash & points
  • Learn & ask questions
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
261 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
Free Tool: SSL Checker

Scans your site and returns information about your SSL implementation and certificate. Helpful for debugging and validating your SSL configuration.

One of a set of tools we are providing to everyone as a way of saying thank you for being a part of the community.

 

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
 

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

Free Tool: SSL Checker

Scans your site and returns information about your SSL implementation and certificate. Helpful for debugging and validating your SSL configuration.

One of a set of tools we are providing to everyone as a way of saying thank you for being a part of the community.

Question has a verified solution.

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

I have helped a lot of people on EE with their coding sources and have enjoyed near about every minute of it. Sometimes it can get a little tedious but it is always a challenge and the one thing that I always say is:  The Exchange of information …
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…
The Email Laundry PDF encryption service allows companies to send confidential encrypted  emails to anybody. The PDF document can also contain attachments that are embedded in the encrypted PDF. The password is randomly generated by The Email Laundr…
A short tutorial showing how to set up an email signature in Outlook on the Web (previously known as OWA). For free email signatures designs, visit https://www.mail-signatures.com/articles/signature-templates/?sts=6651 If you want to manage em…

839 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