Wrox Programmer Forums
|
ASP Forms As of Oct 5, 2005, this forum is now locked. Please use "Classic ASP beginner" at http://p2p.wrox.com/forum.asp?FORUM_ID=54 or "Classic ASP Professional" http://p2p.wrox.com/forum.asp?FORUM_ID=56 instead.
Welcome to the p2p.wrox.com Forums.

You are currently viewing the ASP Forms section of the Wrox Programmer to Programmer discussions. This is a community of software programmers and website developers including Wrox book authors and readers. New member registration was closed in 2019. New posts were shut off and the site was archived into this static format as of October 1, 2020. If you require technical support for a Wrox book please contact http://hub.wiley.com
 
Old December 28th, 2004, 10:34 AM
Registered User
 
Join Date: Dec 2004
Posts: 4
Thanks: 0
Thanked 0 Times in 0 Posts
Default changing a checkbox value by using UPDATE?

I got the following code on my form page:

<%
    Dim Connection
    Dim Recordset
    Dim SQL
    Dim admincheck
    Dim admincheck2
    Dim uitgebreidcheck
    Dim uitgebreidcheck2

    Set Recordset = Server.CreateObject("ADODB.Recordset")
    Set Connection = Server.CreateObject("ADODB.Connection")

            Call Connection.Open("DRIVER={Microsoft Access Driver (*.mdb)};" & _
            "DBQ=" & Server.MapPath("HelpdeskI&A.mdb"))

            SQL = "SELECT * FROM tbl_klanten WHERE naam = '" & Request.Form("edtcontactpersoon") & "' "
        Call Recordset.Open(SQL, Connection)

       admincheck = CBool(Recordset("admin"))
       uitgebreidcheck = CBool(Recordset("uitgebreid"))


    If admincheck = True Then
admincheck2 = 1
Else
admincheck2 = 0
end if

    If uitgebreidcheck = True Then
uitgebreidcheck2 = 1
Else
uitgebreidcheck2 = 0
end if

%>


There are 2 checkboxes:

<input type="checkbox" name="edtuitgebreid" value="<%=CBool(uitgebreidcheck2)%>"<%if CBool(uitgebreidcheck2) Then Response.Write "checked" Else Response.Write "unchecked"%>>

and

<input type="checkbox" name="edtadmin" value="<%=CBool(admincheck2)%>"<%if CBool(admincheck2) Then Response.Write "checked" Else Response.Write "unchecked"%>>


When i submit my form, the following asp code will be launched:


<%
    Dim Connection
    Dim Recordset
    Dim SQL
    Dim admincheck
    Dim uitgebreidcheck

    Set Recordset = Server.CreateObject("ADODB.Recordset")
    Set Connection = Server.CreateObject("ADODB.Connection")


        Call Connection.Open("DRIVER={Microsoft Access Driver (*.mdb)};" & _
            "DBQ=" & Server.MapPath("HelpdeskI&A.mdb"))

admincheck = CBool(Request.Form("edtadmin"))
uitgebreidcheck = CBool(Request.Form("edtuitgebreid"))

    SQL = "UPDATE tbl_klanten SET username = '" _
     & Request ("edtusername") & "', " & _
     "admin = '" & ("admincheck") & "', " & _
     "uitgebreid = '" & uitgebreidcheck & "', " & _
     "password = '" & Request ("edtpassword") & "' WHERE " & _
     "tbl_klanten.naam = '" & Request ("edtcontactpersoon") & "'"


   Call Recordset.Open(SQL, Connection)


%>


Unfortunately something goes wrong, i get the following error:

Microsoft OLE DB Provider for ODBC Drivers (0x80040E07)
[Microsoft][ODBC Microsoft Access-stuurprogramma] Gegevenstypen komen niet overeen in criteriumexpressie.
/Website/beheer_gebruiker_aanpassen_query.asp, line 30

POST Data:
edtcontactpersoon=Prijs&edtusername=P670850&edtpas sword=5t3bmtrp&edtuitgebreid=True&edtadmin=True&ve rzenden=Verstuur

(in english = TYPE mismatch )
Something goes wrong with the checkboxes and their values (1 or true or..) so they cannot be updated in the database but i dont know what ;(. In the database both columns are (yes/no) checks

Any help is appreciated :)

 
Old December 29th, 2004, 12:25 AM
Friend of Wrox
 
Join Date: Sep 2004
Posts: 104
Thanks: 0
Thanked 0 Times in 0 Posts
Send a message via AIM to sureshbabu Send a message via Yahoo to sureshbabu
Default

Hi, i hope you will understand by seeing the following code.
Thanks
Suresh



This is the front end(While displaying)
-------------------------
<%@ Language=VBScript %>
<%
'Here Open Recordset ..Suppose Recordset name is objRs and x and y are the fileds in the database Then
Dim checkX
Dim checkY
If objRs("x") = 1 Then
    checkX = "Checked"
Else
    ckeckX =""
End if
If objRs("y") = 1 Then
    checkY ="Checked"
Else
    checkY =""
End If
%>
<HTML>
<HEAD>
<META NAME="GENERATOR" Content="Microsoft Visual Studio 6.0">
</HEAD>
<BODY>
<form name=fCheck action=check.asp method=post>
X:<input type=checkbox name=x <%=checkX%>><br>
Y:<input type=checkbox name=y <%=checkY%>>
<input type=submit value=submit>
</form>
<P>&nbsp;</P>

</BODY>
</HTML>
----------------------------------------------------------------

While Saving do as follows..
----------------------


But evn in database you have "Yes/No" you can send values as "1" or "0". If you send "1" it will be checked" and if we send "0" it will be unchecked. When ever you are retriving you will get values like "1" or "0".
While saving do as follows.
Dim xCheck
Dim yCheck
If Request.form("x") ="on" Then
    xCheck = 1
Else
    xCheck=0
End If
If Request.form("y") ="on" Then
    yCheck = 1
Else
    yCheck=0
End If


Now save these two values(xCheck,yCheck) into database.










Similar Threads
Thread Thread Starter Forum Replies Last Post
Beginning ASP 3.0: changing text field to checkbox AlanM Classic ASP Basics 0 July 1st, 2007 03:36 AM
update database with checkbox mike7510uk ASP.NET 2.0 Basics 1 December 12th, 2006 07:10 AM
checkbox update keyvanjan Classic ASP Basics 9 April 24th, 2006 10:10 PM
checkbox update keyvanjan Classic ASP Professional 1 April 18th, 2006 06:41 PM
Changing Checkbox Names deminpa Classic ASP Basics 1 August 4th, 2005 06:03 PM





Powered by vBulletin®
Copyright ©2000 - 2020, Jelsoft Enterprises Ltd.
Copyright (c) 2020 John Wiley & Sons, Inc.