|
|
|||||||||
|
|||||||||
|
|||||||||
| |
||
| |||||||||
![]() |
|
|
«
Previous Thread
|
Next Thread
»
|
Thread Tools | Search this Thread | Rate Thread | Display Modes |
|
#1
|
|||
|
|||
|
SELECT a ROW using COOKIE data
OK, im not great at all this!
I have form that checks the two inputs against a table and forwards to a new page if the data is verified within the DB. That works. Im having problems displaying the data from the form on the 2nd page - forget that! im now using a cookie for a differnt reason The cookie stores the 1st input [a membership number] which is unique to all rows and i want to use that cookie to pull off the details belonging to that mebership number... how? i can never get these bits right. |
|
#2
|
||||
|
||||
|
just run a query against the database passing the membership number as a parameter.
Code:
Set Conn = Server.CreateObject("ADODB.Connection")
Set Rs = Server.CreateObject("ADODB.Recordset")
Conn.Open (your connectionstring)
'I am assuming the membership number is only numbers.
Rs = Conn.Execute("SELECT * FROM tableName WHERE memNum = " & the memNum)
If(Rs.eof) Then
Response.write("nothing found")
Else
do until Rs.eof
Write the record info
Rs.movenext
loop
End If
Conn.close
Set Rs = nothing
Set Conn = nothing
|
|
#3
|
|||
|
|||
|
The only way i can kinda explain what i am trying to do is to show you this terribly wrong bit of code, so it hopefully gives you an idea
Code:
SELECT *
FROM dbo.Member_Data
WHERE (userDetails.Fields.Item("Member_Num").Value)" = "(XMreadCookie('myCookie'))"
Heres my form and the cookie details. I dont understand the SQL query you wrote Quote:
Code:
<%@LANGUAGE="VBSCRIPT" CODEPAGE="1252"%>
<!--#include file="Connections/Poll_YMS.asp" -->
<%
Dim userCheck
Dim userCheck_numRows
Set userCheck = Server.CreateObject("ADODB.Recordset")
userCheck.ActiveConnection = MM_Poll_YMS_STRING
userCheck.Source = "SELECT * FROM dbo.Member_Data"
userCheck.CursorType = 0
userCheck.CursorLocation = 2
userCheck.LockType = 1
userCheck.Open()
userCheck_numRows = 0
%>
<%
' *** Validate request to log in to this site.
MM_LoginAction = Request.ServerVariables("URL")
If Request.QueryString<>"" Then MM_LoginAction = MM_LoginAction + "?" + Request.QueryString
MM_valUsername=CStr(Request.Form("Member_Num"))
If MM_valUsername <> "" Then
MM_fldUserAuthorization=""
MM_redirectLoginSuccess="form.asp"
MM_redirectLoginFailed="index.asp"
MM_flag="ADODB.Recordset"
set MM_rsUser = Server.CreateObject(MM_flag)
MM_rsUser.ActiveConnection = MM_Poll_YMS_STRING
MM_rsUser.Source = "SELECT Member_Num, DOB"
If MM_fldUserAuthorization <> "" Then MM_rsUser.Source = MM_rsUser.Source & "," & MM_fldUserAuthorization
MM_rsUser.Source = MM_rsUser.Source & " FROM dbo.Member_Data WHERE Member_Num='" & Replace(MM_valUsername,"'","''") &"' AND DOB='" & Replace(Request.Form("DOB"),"'","''") & "'"
MM_rsUser.CursorType = 0
MM_rsUser.CursorLocation = 2
MM_rsUser.LockType = 3
MM_rsUser.Open
If Not MM_rsUser.EOF Or Not MM_rsUser.BOF Then
' username and password match - this is a valid user
Session("MM_Username") = MM_valUsername
If (MM_fldUserAuthorization <> "") Then
Session("MM_UserAuthorization") = CStr(MM_rsUser.Fields.Item(MM_fldUserAuthorization ).Value)
Else
Session("MM_UserAuthorization") = ""
End If
if CStr(Request.QueryString("accessdenied")) <> "" And false Then
MM_redirectLoginSuccess = Request.QueryString("accessdenied")
End If
MM_rsUser.Close
Response.Redirect(MM_redirectLoginSuccess)
End If
MM_rsUser.Close
Response.Redirect(MM_redirectLoginFailed)
End If
%>
</HEAD>
<script language="JavaScript" type="text/JavaScript">
<!--
function MM_findObj(n, d) { //v4.01
var p,i,x; if(!d) d=document; if((p=n.indexOf("?"))>0&&parent.frames.length) {
d=parent.frames[n.substring(p+1)].document; n=n.substring(0,p);}
if(!(x=d[n])&&d.all) x=d.all[n]; for (i=0;!x&&i<d.forms.length;i++) x=d.forms[i][n];
for(i=0;!x&&d.layers&&i<d.layers.length;i++) x=MM_findObj(n,d.layers[i].document);
if(!x && d.getElementById) x=d.getElementById(n); return x;
}
function MM_setTextOfTextfield(objName,x,newText) { //v3.0
var obj = MM_findObj(objName); if (obj) obj.value = newText;
}
//-->
</script>
<script language="JavaScript" type="text/JavaScript">
<!--
function XMwriteCookie(n,i,t){
var ep="";if (t){d = new Date();d.setTime(d.getTime()+(t*86400000));
ep = "; expires="+d.toGMTString();}document.cookie = n+"="+i+ep+"; path=/";
}
//-->
</script>
<BODY>
<TABLE WIDTH="100%" BORDER="0" CELLSPACING="0" CELLPADDING="0">
<TR>
<TD ALIGN="CENTER" VALIGN="MIDDLE"> <P><FONT SIZE="2" FACE="Arial, Helvetica, sans-serif">Please
enter your details below to gain access to the online poll. </FONT></P>
<P><FONT SIZE="2" FACE="Arial, Helvetica, sans-serif"><IMG SRC="http://www.imeche.org.uk/images/logo.gif"></FONT></P>
<TABLE WIDTH="100" BORDER="1" ALIGN="CENTER" CELLPADDING="5" CELLSPACING="5">
<TR>
<TD><FORM ACTION="<%=MM_LoginAction%>" METHOD="POST" NAME="Check_Membership" ID="Check_Membership">
<P ALIGN="CENTER"> <FONT SIZE="2" FACE="Arial, Helvetica, sans-serif"><STRONG>Membership
Number</STRONG></FONT> <FONT SIZE="2" FACE="Arial, Helvetica, sans-serif">
<INPUT NAME="Member_Num" TYPE="text" ID="Member_Num" onBlur="XMwriteCookie('Member_Num',MM_findObj('Member_Num' ).value,30)">
<STRONG>DOB</STRONG>
<INPUT NAME="DOB" TYPE="text" ID="DOB" onFocus="MM_setTextOfTextfield('DOB','',' ')" VALUE="dd/mm/yyyy">
<BR>
<INPUT TYPE="submit" NAME="Submit" VALUE="Submit">
</FONT></P>
</FORM></TD>
</TR>
</TABLE>
</TD>
</TR>
</TABLE>
</BODY>
</HTML>
<%
userCheck.Close()
Set userCheck = Nothing
%>
![]() Last edited by ThePaulius : January 8th, 2004 at 11:39 AM. |
|
#4
|
||||
|
||||
|
It appears that you are letting Dreamweaver write the code for you?....Not a good idea!
Code:
Set Conn = Server.CreateObject("ADODB.Connection")
Set Rs = Server.CreateObject("ADODB.Recordset")
Conn.Open (your connectionstring)
'I am assuming the membership number is only numbers.
Rs = Conn.Execute("SELECT * FROM Member_Data WHERE Member_Num = " & XMreadCookie('myCookie'))
If(Rs.eof) Then
Response.write("nothing found")
Else
do until Rs.eof
Write the record info
Rs.movenext
loop
End If
Conn.close
Set Rs = nothing
Set Conn = nothing
|
|
#5
|
|||
|
|||
|
Thanks for that, makes abit more sense,
i get this in the browser : Code:
Microsoft VBScript compilation error '800a03ea'
Syntax error
/poll_yms/form.asp, line 13
Rs = Conn.Execute("SELECT * FROM Member_Data WHERE Member_Num = " & XMreadCookie('memberCookie'))
---------------------------------------------------------------------------------^
here's the form.asp - obviously i changed the passwords etc Code:
<%@LANGUAGE="VBSCRIPT" CODEPAGE="1252"%>
<HTML>
<HEAD>
<TITLE>Form</TITLE>
<META HTTP-EQUIV="Content-Type" CONTENT="text/html; charset=iso-8859-1">
</HEAD>
<% Set Conn = Server.CreateObject("ADODB.Connection")
Set Rs = Server.CreateObject("ADODB.Recordset")
Conn.Open ("Provider=SQLOLEDB;Persist Security Info=False;Data Source=123.123.123.123;Initial Catalog=poll_yms;User ID=auser;Password=mypassword")
'I am assuming the membership number is only numbers.
Rs = Conn.Execute("SELECT * FROM Member_Data WHERE Member_Num = " & XMreadCookie('memberCookie'))
If(Rs.eof) Then
Response.write("nothing found")
Else
do until Rs.eof
Write the record info
Rs.movenext
loop
End If
Conn.close
Set Rs = nothing
Set Conn = nothing
%>
<BODY>
</BODY>
</HTML>
|
|
#6
|
||||
|
||||
|
Try changing it to this
Code:
Rs = Conn.Execute("SELECT * FROM Member_Data WHERE Member_Num = " & XMreadCookie("memberCookie"))
|
|
#7
|
|||
|
|||
|
Will do, and also, shouldnt the red code below be something differnet like WRITE Rs or something?
Code:
If(Rs.eof) Then
Response.write("nothing found")
Else
do until Rs.eof
Write the record info
Rs.movenext
loop
End If
Microsoft VBScript compilation error '800a0401' Expected end of statement /poll_yms/form.asp, line 21 Write the record info ----------^ |
|
#8
|
||||
|
||||
|
Quote:
I was trying to explain that, that was the area in the code where you would "Write the record info" from the database...using Response.write. |
![]() |
| Viewing: ASP Free Forums > Database > SQL Development > SELECT a ROW using COOKIE data |
| Thread Tools | Search this Thread |
| Display Modes | Rate This Thread |
|
|
|
|