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
258 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
How your wiki can always stay up-to-date

Quip doubles as a “living” wiki and a project management tool that evolves with your organization. As you finish projects in Quip, the work remains, easily accessible to all team members, new and old.
- Increase transparency
- Onboard new hires faster
- Access from mobile/offline

 

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

What Should I Do With This Threat Intelligence?

Are you wondering if you actually need threat intelligence? The answer is yes. We explain the basics for creating useful threat intelligence.

Join & Write a Comment

I recently decide that I needed a way to make my pages scream on the net.   While searching around how I can accomplish this I stumbled across a great article that stated "minimize the server requests." I got to thinking, hey, I use more than one…
Have you ever needed to get an ASP script to wait for a while? I have, just to let something else happen. Or in my case, to allow other stuff to happen while I was murdering my MySQL database with an update. The Original Issue This was written…
In this tutorial you'll learn about bandwidth monitoring with flows and packet sniffing with our network monitoring solution PRTG Network Monitor (https://www.paessler.com/prtg). If you're interested in additional methods for monitoring bandwidt…
Polish reports in Access so they look terrific. Take yourself to another level. Equations, Back Color, Alternate Back Color. Write easy VBA Code. Tighten space to use less pages. Launch report from a menu, considering criteria only when it is filled…

744 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

13 Experts available now in Live!

Get 1:1 Help Now