SQL Development
 
Forums: » Register « |  User CP |  Games |  Calendar |  Members |  FAQs |  Sitemap |  Support | 
 
 
User Name:
Password:
Remember me
Go Back   ASP Free ForumsDatabaseSQL Development

Reply
Add This Thread To:
  Del.icio.us   Digg   Google   Spurl   Blink   Furl   Simpy   Y! MyWeb 
Thread Tools Search this Thread Rate Thread Display Modes
 
Unread ASP Free Forums Sponsor:
  #1  
Old January 8th, 2004, 10:46 AM
ThePaulius ThePaulius is offline
Registered User
ASP Free Newbie (0 - 499 posts)
 
Join Date: Jan 2004
Location: London
Posts: 17 ThePaulius User rank is Just a Lowly Private (1 - 20 Reputation Level) 
Time spent in forums: < 1 sec
Reputation Power: 0
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.

Reply With Quote
  #2  
Old January 8th, 2004, 10:59 AM
Memnoch's Avatar
Memnoch Memnoch is offline
Unholy Moderator
Click here for more information.
 
Join Date: Oct 2003
Location: In hell, where did you think?
Posts: 11,781 Memnoch User rank is Lieutenant Colonel (40000 - 50000 Reputation Level)Memnoch User rank is Lieutenant Colonel (40000 - 50000 Reputation Level)Memnoch User rank is Lieutenant Colonel (40000 - 50000 Reputation Level)Memnoch User rank is Lieutenant Colonel (40000 - 50000 Reputation Level)Memnoch User rank is Lieutenant Colonel (40000 - 50000 Reputation Level)Memnoch User rank is Lieutenant Colonel (40000 - 50000 Reputation Level)Memnoch User rank is Lieutenant Colonel (40000 - 50000 Reputation Level)Memnoch User rank is Lieutenant Colonel (40000 - 50000 Reputation Level)Memnoch User rank is Lieutenant Colonel (40000 - 50000 Reputation Level)Memnoch User rank is Lieutenant Colonel (40000 - 50000 Reputation Level)Memnoch User rank is Lieutenant Colonel (40000 - 50000 Reputation Level) 
Time spent in forums: 3 Weeks 5 Days 8 h 45 m 55 sec
Reputation Power: 470
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

Reply With Quote
  #3  
Old January 8th, 2004, 11:30 AM
ThePaulius ThePaulius is offline
Registered User
ASP Free Newbie (0 - 499 posts)
 
Join Date: Jan 2004
Location: London
Posts: 17 ThePaulius User rank is Just a Lowly Private (1 - 20 Reputation Level) 
Time spent in forums: < 1 sec
Reputation Power: 0
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:
memNum = " & the memNum)


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.

Reply With Quote
  #4  
Old January 8th, 2004, 12:20 PM
Memnoch's Avatar
Memnoch Memnoch is offline
Unholy Moderator
Click here for more information.
 
Join Date: Oct 2003
Location: In hell, where did you think?
Posts: 11,781 Memnoch User rank is Lieutenant Colonel (40000 - 50000 Reputation Level)Memnoch User rank is Lieutenant Colonel (40000 - 50000 Reputation Level)Memnoch User rank is Lieutenant Colonel (40000 - 50000 Reputation Level)Memnoch User rank is Lieutenant Colonel (40000 - 50000 Reputation Level)Memnoch User rank is Lieutenant Colonel (40000 - 50000 Reputation Level)Memnoch User rank is Lieutenant Colonel (40000 - 50000 Reputation Level)Memnoch User rank is Lieutenant Colonel (40000 - 50000 Reputation Level)Memnoch User rank is Lieutenant Colonel (40000 - 50000 Reputation Level)Memnoch User rank is Lieutenant Colonel (40000 - 50000 Reputation Level)Memnoch User rank is Lieutenant Colonel (40000 - 50000 Reputation Level)Memnoch User rank is Lieutenant Colonel (40000 - 50000 Reputation Level) 
Time spent in forums: 3 Weeks 5 Days 8 h 45 m 55 sec
Reputation Power: 470
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

Reply With Quote
  #5  
Old January 8th, 2004, 12:36 PM
ThePaulius ThePaulius is offline
Registered User
ASP Free Newbie (0 - 499 posts)
 
Join Date: Jan 2004
Location: London
Posts: 17 ThePaulius User rank is Just a Lowly Private (1 - 20 Reputation Level) 
Time spent in forums: < 1 sec
Reputation Power: 0
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>

Reply With Quote
  #6  
Old January 8th, 2004, 01:19 PM
Memnoch's Avatar
Memnoch Memnoch is offline
Unholy Moderator
Click here for more information.
 
Join Date: Oct 2003
Location: In hell, where did you think?
Posts: 11,781 Memnoch User rank is Lieutenant Colonel (40000 - 50000 Reputation Level)Memnoch User rank is Lieutenant Colonel (40000 - 50000 Reputation Level)Memnoch User rank is Lieutenant Colonel (40000 - 50000 Reputation Level)Memnoch User rank is Lieutenant Colonel (40000 - 50000 Reputation Level)Memnoch User rank is Lieutenant Colonel (40000 - 50000 Reputation Level)Memnoch User rank is Lieutenant Colonel (40000 - 50000 Reputation Level)Memnoch User rank is Lieutenant Colonel (40000 - 50000 Reputation Level)Memnoch User rank is Lieutenant Colonel (40000 - 50000 Reputation Level)Memnoch User rank is Lieutenant Colonel (40000 - 50000 Reputation Level)Memnoch User rank is Lieutenant Colonel (40000 - 50000 Reputation Level)Memnoch User rank is Lieutenant Colonel (40000 - 50000 Reputation Level) 
Time spent in forums: 3 Weeks 5 Days 8 h 45 m 55 sec
Reputation Power: 470
Try changing it to this
Code:
Rs = Conn.Execute("SELECT * FROM Member_Data WHERE Member_Num = " & XMreadCookie("memberCookie"))

Reply With Quote
  #7  
Old January 9th, 2004, 06:24 AM
ThePaulius ThePaulius is offline
Registered User
ASP Free Newbie (0 - 499 posts)
 
Join Date: Jan 2004
Location: London
Posts: 17 ThePaulius User rank is Just a Lowly Private (1 - 20 Reputation Level) 
Time spent in forums: < 1 sec
Reputation Power: 0
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
----------^

Reply With Quote
  #8  
Old January 9th, 2004, 08:56 AM
Memnoch's Avatar
Memnoch Memnoch is offline
Unholy Moderator
Click here for more information.
 
Join Date: Oct 2003
Location: In hell, where did you think?
Posts: 11,781 Memnoch User rank is Lieutenant Colonel (40000 - 50000 Reputation Level)Memnoch User rank is Lieutenant Colonel (40000 - 50000 Reputation Level)Memnoch User rank is Lieutenant Colonel (40000 - 50000 Reputation Level)Memnoch User rank is Lieutenant Colonel (40000 - 50000 Reputation Level)Memnoch User rank is Lieutenant Colonel (40000 - 50000 Reputation Level)Memnoch User rank is Lieutenant Colonel (40000 - 50000 Reputation Level)Memnoch User rank is Lieutenant Colonel (40000 - 50000 Reputation Level)Memnoch User rank is Lieutenant Colonel (40000 - 50000 Reputation Level)Memnoch User rank is Lieutenant Colonel (40000 - 50000 Reputation Level)Memnoch User rank is Lieutenant Colonel (40000 - 50000 Reputation Level)Memnoch User rank is Lieutenant Colonel (40000 - 50000 Reputation Level) 
Time spent in forums: 3 Weeks 5 Days 8 h 45 m 55 sec
Reputation Power: 470
Quote:
Originally posted by ThePaulius
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
----------^

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.

Reply With Quote
Reply

Viewing: ASP Free ForumsDatabaseSQL Development > SELECT a ROW using COOKIE data


Thread Tools  Search this Thread 
Search this Thread:

Advanced Search
Display Modes  Rate This Thread 
Rate This Thread:


Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

vB code is On
Smilies are On
[IMG] code is On
HTML code is Off
View Your Warnings | New Posts | Latest News | Latest Threads | Shoutbox
Forum Jump


Forums: » Register « |  User CP |  Games |  Calendar |  Members |  FAQs |  Sitemap |  Support | 
  
 





© 2003-2008 by Developer Shed. All rights reserved. DS Cluster 1 hosted by Hostway
Stay green...Green IT