?
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
?
266 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
Industry Leaders: 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

Concerto Cloud for Software Providers & ISVs

Can Concerto Cloud Services help you focus on evolving your application offerings, while delivering the best cloud experience to your customers? From DevOps to revenue models and customer support, the answer is yes!

Learn how Concerto can help you.

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…
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…
Whether it be Exchange Server Crash Issues, Dirty Shutdown Errors or Failed to mount error, Stellar Phoenix Mailbox Exchange Recovery has always got your back. With the help of its easy to understand user interface and 3 simple steps recovery proced…
As many of you are aware about Scanpst.exe utility which is owned by Microsoft itself to repair inaccessible or damaged PST files, but the question is do you really think Scanpst.exe is capable to repair all sorts of PST related corruption issues?
Suggested Courses
Course of the Month15 days, 2 hours left to enroll

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