?
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
Medium Priority
?
264 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
[X]
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
  • 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
Technology Partners: We Want Your Opinion!

We value your feedback.

Take our survey and automatically be enter to win anyone of the following:
Yeti Cooler, Amazon eGift Card, and Movie eGift Card!

 

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

[Webinar] How Hackers Steal Your Credentials

Do You Know How Hackers Steal Your Credentials? Join us and Skyport Systems to learn how hackers steal your credentials and why Active Directory must be secure to stop them.

Question has a verified solution.

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

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…
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…
Monitoring a network: how to monitor network services and why? Michael Kulchisky, MCSE, MCSA, MCP, VTSP, VSP, CCSP outlines the philosophy behind service monitoring and why a handshake validation is critical in network monitoring. Software utilized …
Add bar graphs to Access queries using Unicode block characters. Graphs appear on every record in the color you want. Give life to numbers. Hopes this gives you ideas on visualizing your data in new ways ~ Create a calculated field in a query: …
Suggested Courses

762 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