|
 |
access_asp thread: How do I Reload data and session variable mixing?
Message #1 by "Cookie" <abdulm7@h...> on Sat, 8 Sep 2001 01:15:40 +0100
|
|
Hi,
I need help please. What i'm trying to do is build a site were kids can do
there
Assignments, save it, login later and edit it and then finaly, submit it for
marking... at the moment i can save data and the data is visiable while they
are logged
in.......
However, there are two problems:
1..... if the user enter data in one of the assignments, the save it, and
goes to
another assignemnt. Then vaules of Assignemnt 1 appear on Assignemt 2..
2..... when the user logs out and then logins. The entered data does not
appear
on the fields of the Assignemnts the user has saved....
How can I reload the data from the DB for each assignemnt and stop the
values of one
assignment appearing on the other...?
At the moment the codes has no errors, but but still, my program does not
work...
Please advise or show me were i'm going wrong... Thank you in advance...
********* Assignemnt1.asp and Assignment2.asp are the same, but with
different questions***********
<html>
....
...
<BR> <BR>
<%
If Request("Update") = "True" Then
Response.Write "<center>Amend/update your answers <STRONG>Assingmnet
2</STRONG></center><P>"
Else
If Request("NotFound") = "True" Then
Response.Write "<I>You have not started the assignment. " & _
"Do you wish to start it now?.</I><P>"
Else
Response.Write "<CENTER>(If you have finished this assignmtnt, " & _
"you might want to start the next one.)</CENTER>"
End If
End If
Response.Write "<center>Think and take time in answersing the question
</Center>"
dim Asconst ' To be used in the ????Save.asp so the
right
Questionset is
Asconst = "QuestionSet2" ' called and updated....
%>
<P><p>
<FORM ACTION="tempSave.asp" NAME="qSet" METHOD="POST">
<TABLE BORDER=0>
<TR>
<TD WIDTH=20% ROWSPAN=11> </TD>
<TD><b>Who is pink?</b></TD>
<TD><INPUT TYPE="Text" NAME="quest1" VALUE="<%
Session("Question1")%>"
SIZE="40"></TD>
</TR>
<TR>
<TD height="29"><b>How have is the Sun?:</b></TD>
<TD height="29">
<INPUT TYPE="Text" NAME="quest2" VALUE="<%= Session("Question2")%>"
SIZE="40"></TD>
</TR>
<TR>
<TD><b>What do ID mean?:</b></TD>
<TD><INPUT TYPE="Text" NAME="quest3" VALUE="<%
Session("Question3")%>"
SIZE="40"></TD>
</TR>
<TR>
<TD><b>which plante do you come from?</b></TD>
<TD><INPUT TYPE="Text" NAME="quest4" VALUE="<%
Session("Question4")%>"
SIZE="40"></TD>
</TR> <input type="hidden" name="AssignConst" value="<%=Asconst %>">
<TR>
<TD>
<TD ALIGN=CENTER height="53">
<input type="Submit" value="Save Your Work"
name="Submit"><P>
<input type="RESET" name="RESET">
</TD>
<TD ALIGN=CENTER COLSPAN=2 height="53"><BR>
<P>
</TD>
</TR>
</TABLE>
</FORM>
<FORM name="FAform" method="post" action="PermSave.asp">
<input type="hidden" name="hquest1" value="<%
Session("Question1")%>">
<input type="hidden" name="hquest2" value="<%
Session("Question2")%>">
<input type="hidden" name="hquest3" value="<%
Session("Question3")%>">
<input type="hidden" name="hquest4" value="<%
Session("Question4")%>">
<input type="hidden" name="AssignConst" value="<%=Asconst %>">
<INPUT TYPE="Submit" VALUE="Submit for Marking">
</FORM>
<P>
....
...
***************TempSame.asp saves the data into a
DB****************************
<!--#include file="Clssfd.asp"-->
<%
Dim rsQuestAns, strQSetNo
strQSetNo= Request.Form("AssignConst")
'Response.Write strQSetNo & " <p>"
Set rsQuestAns = Server.CreateObject("ADODB.Recordset")
rsQuestAns.Open strQSetNo , objConn, adOpenStatic, adLockOptimistic,
adCmdTable
'rsQuestAns.MoveFirst
...don't need
rsQuestAns.Filter = "QPersonID = '" & Session("PersonID") & "'"
If rsQuestAns.EOF Then '
User not found
rsQuestAns.AddNew ' ...so add
a new
record
End If
' write questions answers in to
the record
rsQuestAns("Question1") = Request.Form("quest1")
rsQuestAns("Question2") = Request.Form("quest2")
rsQuestAns("Question3") = Request.Form("quest3")
rsQuestAns("Question4") = Request.Form("quest4")
rsQuestAns("QPersonID") = session("PersonID")
rsQuestAns.Update ' update
the database
Dim strName, strValue ' create session
variables
For each strField in rsQuestAns.Fields
strName = strField.Name
' Response.Write strName & " " ' ... test to see if
code works
strValue = strField.value
' Response.Write strValue & " "
Session(strName) = strValue
Next
Session("blnValidUser") = True ' declare that current user is
validated
if strQsetNo = "QuestionSet1" then ' ... after updating the DB
the
user is re-directed
Response.Redirect "Assignment1.asp" ' ... back to the assignment
they were doing...
else
if strQSetNo = "QuestionSet2" then
Response.Redirect "Assignment2.asp"
else
Response.Redirect "Assignment3.asp"
End If
End if
%>
*********** PermSave.asp check the field data with the answers in the DB and
the
show the user their score. It also emails there answers and score to the
teacher****
NOT YET COMPLETe
Message #2 by "Paul Bruce" <pbruce@c...> on Mon, 24 Sep 2001 06:54:14
|
|
I may be off the planet, as I did find it difficult to see what your
problem was.
Problem 1.
Session variables can be nasty at times, and you are experiencing one of
their nasty features now. If I understand you correctly, the same Session
names are being used for Assignment 1 and Assignment 2.
Don't do this, you are asking for problems.
I really cannot see the need to use Session variables in your problem, so
I would stop using them, and instead use a recordset objects to set the
default value for a text field.
The student identifier could be set in a Session variable however, and
this would be sensible use of Session variables.
So where you have entered something like
<TABLE BORDER=0>
<TR>
<TD WIDTH=20% ROWSPAN=11> </TD>
<TD><b>Who is pink?</b></TD>
<TD><INPUT TYPE="Text" NAME="quest1" VALUE="<%
Session("Question1")%>"
SIZE="40"></TD>
</TR>
<TR>
I would instead use something like
strSQL = "SELECT * FROM assignments " & _
"WHERE userid=" & studentid & _
" AND assignmentnum=" & assignnum
objRec.Open strSQL, objConn, adOpenForwardOnly, adLockReadOnly,
adCmdTable
If Not objRec.EOF Then
Q1 = objRec("question1")
' and so on ....
End if
' and then a slight variation of your code....
<TABLE BORDER=0>
<TR>
<TD WIDTH=20% ROWSPAN=11> </TD>
<TD><b>Who is pink?</b></TD>
<TD><INPUT TYPE="Text" NAME="quest1" VALUE="<% =Q1 %>"
SIZE="40"></TD>
</TR>
<TR>
Your table name appears to be dynamic in TempSame.asp, and I wonder
whether this is really needed.
The problem you are experiencing in your second point appears to be a
session variable nasty as well, my solution above will solve that too.
The absolute most I would use as a session variable is the students user
id, and then rely solely on direct access to the database and forms for
getting and setting values.
Hope this helps.
Paul
|
|
 |