Greetings experts:
How can I modify this code so that it allows me to new records?
Right now, it is over-writing existing records.
Just a brief history: There are 5 categories, category 10, 5,3,2,1. Each category, with the exception of category 2, has 6 subCategories.
The way it works currently is that, if I select a category and click "Submit", the subCategories associated with that category are displayed. I can tben make changes and then submit to the db.
What I would like to do is rather than make changes, I want the subCategories to be submitted as new records.
Any assistance is appreciated.
here is entire working code:
How can I modify this code so that it allows me to new records?
Right now, it is over-writing existing records.
Just a brief history: There are 5 categories, category 10, 5,3,2,1. Each category, with the exception of category 2, has 6 subCategories.
The way it works currently is that, if I select a category and click "Submit", the subCategories associated with that category are displayed. I can tben make changes and then submit to the db.
What I would like to do is rather than make changes, I want the subCategories to be submitted as new records.
Any assistance is appreciated.
here is entire working code:
Code:
<%@LANGUAGE="VBSCRIPT" CODEPAGE="1252"%>
<%
set conn=Server.CreateObject("ADODB.Connection")
conn.Provider="Microsoft.Jet.OLEDB.4.0"
Conn.Open "PROVIDER=Microsoft.Jet.OLEDB.4.0;DATA SOURCE=" & server.mappath("Database/stm.mdb")
If Len(Request.Form) > 0 Then
For Each i In Request.Form("SubCategory")
errMsg = ""
SubCategory = i
BeginCount = Request.Form("BeginCount_" & i)
EndCount = Request.Form("EndCount_" & i)
If Not IsNumeric(SubCategory) Then
errMsg = errMsg & "SubCategory not valid<br>"
End If
If Not IsNumeric(BeginCount) Then
errMsg = errMsg & "BeginCount not valid<br>"
End If
If Not IsNumeric(EndCount) Then
errMsg = errMsg & "EndCount not valid<br>"
End If
If errMsg = "" Then
BeginCount = CDbl(BeginCount)
EndCount = CDbl(EndCount)
If EndCount > BeginCount Then
errMsg = errMsg & "End Count must not be greater than Begin Count<br>"
End If
End If
msg = msg & "<p>SubCategory: " & SubCategory & "<br>"
sql = "UPDATE Lottos SET BeginCount = " & BeginCount &_
", EndCount = " & EndCount &_
", TodayDay = Now()" &_
" WHERE SubCategory = " & SubCategory
'response.write sql
'response.end
If errMsg = "" Then
Conn.Execute(sql)
msg = msg & sql
Else
msg = msg & errMsg
End If
msg = msg & "</p>"
Next
End If
%>
<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN" "(URL address blocked: See forum rules)">
<html>
<head>
<meta http-equiv="Content-Type" content="text/html; charset=iso-8859-1">
<title>New Tickets</title>
</head>
<body>
<div><%=msg%></div>
<%
Set rsCat = Server.CreateObject("ADODB.Recordset")
rsCat.Open "SELECT DISTINCT Category FROM lottos WHERE Category",conn
%>
<form name="form1" method="post" action="">
Choose Category
<select name="Category">
<option value="-1">Choose</option>
<% While Not rsCat.EOF %>
<option value="<%=rsCat("Category")%>"><%=rsCat("Category")%></option>
<% rsCat.MoveNext
Wend
rsCat.Close
set rsCat = Nothing
%>
</select>
<input type="submit" name="Submit" value="Submit">
</form>
<p>
<%
If Request.Form("Category") > 0 Then
cat = Replace(Request.Form("Category"),"'","''")
Set rs = Server.CreateObject("ADODB.Recordset")
rs.Open "SELECT * FROM lottos WHERE Category = " & cat,conn
%>
<form name="Category<%=rs("Category")%>" method="post" action="">
<p>Working on SubCategoryegories from Category <%=cat%></p>
<table border="1" cellpadding="5" cellspacing="0">
<tr>
<td>SubCategory</td>
<td>BeginCount</td>
<td>EndCount</td>
</tr>
<% While Not rs.EOF %>
<tr>
<td><input type="text" name="SubCategory" value="<%=rs("SubCategory")%>" readonly="readonly"></td>
<td><input type="text" name="BeginCount_<%=rs("SubCategory")%>" value="<%=rs("BeginCount")%>"></td>
<td><input type="text" name="EndCount_<%=rs("SubCategory")%>" value="<%=rs("EndCount")%>"></td>
</tr>
<% rs.moveNext
Wend
%>
</table>
<input type="submit" name="submit" value="Submit">
</form>
<%
End If
'rs.Close
set rs = Nothing
conn.close
set conn = Nothing
%>
</body>
</html>