I need help with a loop to save change on page 2 that where selected on page 1
Page 1 - lists all games owned by a users, a check box shows which games the user has.
page 2 - is called when the user clicks the save button.
the following code works, it addes the user to the user table, and one static record to the gamesOwners table.
what I need it how do I loop thru and read the GameIds on page 1.
I've only be code asp for the last three days.
so if there is a way to only have 1 page, great!
otherwise what do I need to finish this code.
TIA
Tim
Page 2 code---
<html>
<head>
<title>ADO - Submit DataBase Record</title>
</head>
<body>
<h2>Submit to Database</h2>
<%on error resume next
dim conn,rs ,x , objErr
set conn=Server.CreateObject("ADODB.Connection")
conn.Provider="Microsoft.Jet.OLEDB.4.0"
conn.open(server.mappath("\db\database.mdb"))
' add new owner to table
sql="INSERT INTO tblGameOwners ( Name ) Values ('" & Request.Form("fname") & "')"
'sql="INSERT INTO tblGameOwners ( Name ) Values ('test')"
'on error resume next
conn.Execute sql
if err.number<>0 then
Response.Write("No update permissions!" & err.number & " " & sql)
else
Response.Write("<h3>" & recaffected & " record added (name)</h3>")
end if
' get autonumber id for new owner
set rs=Server.CreateObject("ADODB.Recordset")
rs.open "SELECT ID FROM tblGameOwners where name = '" & Request.Form("fname") & "'",conn
' add games to ownerGames for new owner
for each x in rs.Fields
if x.name="ID" then
' for x = 1 to totalRowsIn Screen1 ( need loop code )
sql="INSERT INTO tblOwnerGames ( OwnerID , GameId) Values (" & x.value & " , 1)"
'Next
conn.Execute sql
if err.number<>0 then
Response.Write("No update permissions!" & err.number & " " & sql)
else
Response.Write("<h3>" & recaffected & " record added (games)</h3>")
end if
end if
next
conn.close
set Conn = nothing %>
<br></br>
<br></br>
<br></br>
<br></br>
<h6>AdoInsertNew </h6>
</body>
</html>
page 1 code ----
<%
id=Request.Form("id")
Session("sID")=id
if id="" then response.end
set conn=Server.CreateObject("ADODB.Connection")
conn.provider="Microsoft.Jet.OLEDB.4.0"
conn.open(server.mappath("\db\database.mdb"))
set rs = Server.CreateObject("ADODB.Recordset")
rs.Open "SELECT tblGamesList.gameID, tblGamesList.gameName, tblGamesList.version, " & _
" (SELECT IIf(Not IsNull([OwnerID]),'1','0') " & _
" FROM tblOwnerGames " & _
" WHERE tblOwnerGames.OwnerID = " & id & " and tblGamesList.gameid =tblOwnerGames.gameID ) AS Owns " & _
" FROM tblGamesList ", conn
set rs2 = Server.CreateObject("ADODB.Recordset")
rs2.Open "SELECT Name " & _
" FROM tblGameOwners " & _
" WHERE ID = " & id , conn
%>
<h2>List Games</h2>
<table border="1" width="25%">
<tr bgcolor="#b0c4de">
<%for each x2 in rs2.Fields
response.write("<th>" & ucase(x2.name) & "</th>")
next %>
</tr>
<tr bgcolor="#f0f0f0">
<%for each x2 in rs2.Fields
%><td><center><%Response.Write(x2.value)%></center></td><%
next %>
</tr>
<table border="1" width="75%">
<tr bgcolor="#b0c4de">
<%
for each x in rs.Fields
if x.name = "gameID" or x.name = "gameName" or x.name = "version" or x.name = "Owns" then%>
<%response.write("<th>" & ucase(x.name) & "</th>")%>
<%end if
next
%>
</tr>
<%do until rs.EOF%>
<tr bgcolor="#f0f0f0">
<form method="post" action="adoEditGame.asp" target="_blank">
<%
for each x in rs.Fields
if x.name="gameID" then%>
<td><center><input type="submit" name="gameID" value="<%=x.value%>"></center></td>
<%elseif x.name = "Owns" Then %>
<% if x.value=1 then %>
<td><center><input type="checkbox" name="Owns" value="<%=x.value%>" checked=""checked"" ></center</td>
<%else%>
<td><center><input type="checkbox" name="Owns" value="<%=x.value%>"></center></td>
<%end if%>
<%elseif x.name = "gameName" then%>
<td><%Response.Write(x.value)%> </td>
<%elseif x.name = "gameID" or x.name = "version" then%>
<td><%Response.Write(x.value)%> </td>
<%end if
next
%>
</form>
<%rs.MoveNext%>
</tr>
<%
loop
rs.close
set rs=nothing
rs2.close
set rs2=nothing
conn.close
set conn=nothing
%>
</table>
<form method="post" action="adoUpdate.asp" target="_blank">
<input type="submit" name="action" value="Save">
<input type="submit" name="action" value="Delete">
</form>
<form method="post" action="adoAddGame.asp" target="_blank">
<input type="submit" name="action" value="Add Game">
</form>
</form>
<br></br>
<br></br>
<br></br>
<br></br>
<h6>AdoEdit </h6>
</body>
</html>
Page 1 - lists all games owned by a users, a check box shows which games the user has.
page 2 - is called when the user clicks the save button.
the following code works, it addes the user to the user table, and one static record to the gamesOwners table.
what I need it how do I loop thru and read the GameIds on page 1.
I've only be code asp for the last three days.
so if there is a way to only have 1 page, great!
otherwise what do I need to finish this code.
TIA
Tim
Page 2 code---
<html>
<head>
<title>ADO - Submit DataBase Record</title>
</head>
<body>
<h2>Submit to Database</h2>
<%on error resume next
dim conn,rs ,x , objErr
set conn=Server.CreateObject("ADODB.Connection")
conn.Provider="Microsoft.Jet.OLEDB.4.0"
conn.open(server.mappath("\db\database.mdb"))
' add new owner to table
sql="INSERT INTO tblGameOwners ( Name ) Values ('" & Request.Form("fname") & "')"
'sql="INSERT INTO tblGameOwners ( Name ) Values ('test')"
'on error resume next
conn.Execute sql
if err.number<>0 then
Response.Write("No update permissions!" & err.number & " " & sql)
else
Response.Write("<h3>" & recaffected & " record added (name)</h3>")
end if
' get autonumber id for new owner
set rs=Server.CreateObject("ADODB.Recordset")
rs.open "SELECT ID FROM tblGameOwners where name = '" & Request.Form("fname") & "'",conn
' add games to ownerGames for new owner
for each x in rs.Fields
if x.name="ID" then
' for x = 1 to totalRowsIn Screen1 ( need loop code )
sql="INSERT INTO tblOwnerGames ( OwnerID , GameId) Values (" & x.value & " , 1)"
'Next
conn.Execute sql
if err.number<>0 then
Response.Write("No update permissions!" & err.number & " " & sql)
else
Response.Write("<h3>" & recaffected & " record added (games)</h3>")
end if
end if
next
conn.close
set Conn = nothing %>
<br></br>
<br></br>
<br></br>
<br></br>
<h6>AdoInsertNew </h6>
</body>
</html>
page 1 code ----
<%
id=Request.Form("id")
Session("sID")=id
if id="" then response.end
set conn=Server.CreateObject("ADODB.Connection")
conn.provider="Microsoft.Jet.OLEDB.4.0"
conn.open(server.mappath("\db\database.mdb"))
set rs = Server.CreateObject("ADODB.Recordset")
rs.Open "SELECT tblGamesList.gameID, tblGamesList.gameName, tblGamesList.version, " & _
" (SELECT IIf(Not IsNull([OwnerID]),'1','0') " & _
" FROM tblOwnerGames " & _
" WHERE tblOwnerGames.OwnerID = " & id & " and tblGamesList.gameid =tblOwnerGames.gameID ) AS Owns " & _
" FROM tblGamesList ", conn
set rs2 = Server.CreateObject("ADODB.Recordset")
rs2.Open "SELECT Name " & _
" FROM tblGameOwners " & _
" WHERE ID = " & id , conn
%>
<h2>List Games</h2>
<table border="1" width="25%">
<tr bgcolor="#b0c4de">
<%for each x2 in rs2.Fields
response.write("<th>" & ucase(x2.name) & "</th>")
next %>
</tr>
<tr bgcolor="#f0f0f0">
<%for each x2 in rs2.Fields
%><td><center><%Response.Write(x2.value)%></center></td><%
next %>
</tr>
<table border="1" width="75%">
<tr bgcolor="#b0c4de">
<%
for each x in rs.Fields
if x.name = "gameID" or x.name = "gameName" or x.name = "version" or x.name = "Owns" then%>
<%response.write("<th>" & ucase(x.name) & "</th>")%>
<%end if
next
%>
</tr>
<%do until rs.EOF%>
<tr bgcolor="#f0f0f0">
<form method="post" action="adoEditGame.asp" target="_blank">
<%
for each x in rs.Fields
if x.name="gameID" then%>
<td><center><input type="submit" name="gameID" value="<%=x.value%>"></center></td>
<%elseif x.name = "Owns" Then %>
<% if x.value=1 then %>
<td><center><input type="checkbox" name="Owns" value="<%=x.value%>" checked=""checked"" ></center</td>
<%else%>
<td><center><input type="checkbox" name="Owns" value="<%=x.value%>"></center></td>
<%end if%>
<%elseif x.name = "gameName" then%>
<td><%Response.Write(x.value)%> </td>
<%elseif x.name = "gameID" or x.name = "version" then%>
<td><%Response.Write(x.value)%> </td>
<%end if
next
%>
</form>
<%rs.MoveNext%>
</tr>
<%
loop
rs.close
set rs=nothing
rs2.close
set rs2=nothing
conn.close
set conn=nothing
%>
</table>
<form method="post" action="adoUpdate.asp" target="_blank">
<input type="submit" name="action" value="Save">
<input type="submit" name="action" value="Delete">
</form>
<form method="post" action="adoAddGame.asp" target="_blank">
<input type="submit" name="action" value="Add Game">
</form>
</form>
<br></br>
<br></br>
<br></br>
<br></br>
<h6>AdoEdit </h6>
</body>
</html>