Jump to content

ASP delete records where checkbox false (with 2 variables)


Recommended Posts

Hiya,

Having considerable trouble due to my inexperience with asp. I don't have time to learn php so that's out.

Basically I've got a Company table and a customer type table, and a customer types table (link table)

Where customer types has the primary keys from the other tables: company type and company

I've made a customer details edit form where you can change all their details in one form so you can edit data from any tables.

When you edit their customer types it'll show checked checkboxes where the customertype from customertypes and the customernumber matches the customer type in Customertype table

So you got it a bit like this:

[x] Type 1 Customer

[ ] Type 2 Customer

[x] Type 3 customer

[x] type 4 customer

OK so what I'm trying to do is compare the values of the checkboxes and if they've changed then delete or insert the values into customertypes as necessary.

I tried to do it with the command function (cos you can't use their insert / delete record thing more than once) in DW but it won't pull the variables out for some reason. Also it doesn't seem to like me having more than one variable.

Anyway here's the section of code (command deleted cos it just kept saying it was wrong):

<%@LANGUAGE="VBSCRIPT" CODEPAGE="1252"%>

<!--#include file="Connections/conn2.asp" -->

<%

Dim Recordset1__CN

Recordset1__CN = "1"

If (Request.Form("CompanyNumber") <> "") Then

Recordset1__CN = Request.Form("CompanyNumber")

End If

%>

<%

Dim Recordset1

Dim Recordset1_numRows

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

Recordset1.ActiveConnection = MM_conn2_STRING

Recordset1.Source = "SELECT * FROM SelectCusType WHERE CompanyNumber=" + Replace(Recordset1__CN, "'", "''") + ""

Recordset1.CursorType = 0

Recordset1.CursorLocation = 2

Recordset1.LockType = 1

Recordset1.Open()

DO WHILE NOT Recordset1.EOF

IF x <> total THEN

CusType = CusType & Recordset1.Fields.Item("Number").Value & ","

ELSE

CusType = CusType & Recordset1.Fields.Item("Number").Value

END IF

x = x + 1

Recordset1.MoveNext

LOOP

Recordset1_numRows = 0

%>

<%

Dim Recordset2

Dim Recordset2_numRows

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

Recordset2.ActiveConnection = MM_conn2_STRING

Recordset2.Source = "SELECT * FROM Company"

Recordset2.CursorType = 0

Recordset2.CursorLocation = 2

Recordset2.LockType = 1

Recordset2.Open()

Recordset2_numRows = 0

%>

<%

Dim Recordset3

Dim Recordset3_numRows

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

Recordset3.ActiveConnection = MM_conn2_STRING

Recordset3.Source = "SELECT * FROM [Customer Type] ORDER BY Number"

Recordset3.CursorType = 0

Recordset3.CursorLocation = 2

Recordset3.LockType = 1

Recordset3.Open()

Recordset3_numRows = 0

%>

<%

Dim Repeat1__numRows

Dim Repeat1__index

Repeat1__numRows = -1

Repeat1__index = 0

Recordset1_numRows = Recordset1_numRows + Repeat1__numRows

%>

<%

Dim Repeat2__numRows

Dim Repeat2__index

Repeat2__numRows = -1

Repeat2__index = 0

Recordset3_numRows = Recordset3_numRows + Repeat2__numRows

%>

<html>

<head>

<title>Untitled Document</title>

<meta http-equiv="Content-Type" content="text/html; charset=iso-8859-1">

</head>

<body>

<form name="crap" >

<input type="text" name="ComNum" value="<%=(Recordset2.Fields.Item("CompanyNumber").Value)%>">

<%

While ((Repeat2__numRows <> 0) AND (NOT Recordset3.EOF))

%>

<input type="checkbox" name="ctcheckbox" value="<%=(Recordset3.Fields.Item("Number").Value)%>"

<% If instr(CusType,Recordset3.Fields.Item("Number").Value) > 0 Then Response.Write("Checked")

%>>

<%=(Recordset3.Fields.Item("Customer Type").Value)%> <br>

<%

Repeat2__index=Repeat2__index+1

Repeat2__numRows=Repeat2__numRows-1

Recordset3.MoveNext()

Wend

%>

<input type="submit" value="go">

</form>

</body>

</html>

<%

Recordset1.Close()

Set Recordset1 = Nothing

%>

<%

Recordset2.Close()

Set Recordset2 = Nothing

%>

<%

Recordset3.Close()

Set Recordset3 = Nothing

%>

Now I'm assuming I've got to do some comparison of the values in the table and then if they#'re different, insert or delete, is this correct?

Any help would be muchly appreciated as I've wasted too many hours battling against DW and ASP!

Link to comment
Share on other sites


Create an account or sign in to comment

You need to be a member in order to leave a comment

Create an account

Sign up for a new account in our community. It's easy!

Register a new account

Sign in

Already have an account? Sign in here.

Sign In Now
  • Recently Browsing   0 members

    • No registered users viewing this page.
×
×
  • Create New...