a webmaster learning community
     Home    Register     Search      Help      Login    
FrontPage Alternative
Sponsors

Hosting from $3.99 per month!

Shopping Cart Software
Ecommerce software integrated into Frontpage, Dreamweaver and Golive templates. No monthly fees and available in ASP and PHP versions. dd

Website Templates
We also have a wide selection of Dreamweaver, Expression Web and Frontpage templates as well as webmaster tools and CSS layouts.

Frontpage website templates
Creative Website Templates for FrontPage, Dreamweaver, Flash, SwishMax

Search Forums
 

Advanced search
Recent Posts

 Todays Posts
 Most Active posts
 Posts since last visit
 My Recent Posts
 Mark posts read

 

passing the ID in response.redirect

 
View related threads: (in this forum | in all forums)

Logged in as: Guest
Users viewing this topic: none
Printable Version 

All Forums >> Web Development >> General Web Development >> passing the ID in response.redirect
Page: [1]
 
AllenD

 

Posts: 258
From: Dayton, OH, USA
Status: offline

 
passing the ID in response.redirect - 9/19/2005 11:17:44   
Hello all, I have the following code and I am having problems passing the ID field in my response.redirect, it is already inside of <% and I cannot figure out how to break out of the <% and back in ?

if session("Uname")<>"" then
response.redirect ("found.asp")

I have tried:

if session("Uname")<>"" then
response.redirect ("found.asp?ID=<%=ID%>")

But this does not work, any ideas?
dpf

 

Posts: 7126
Joined: 11/12/2003
From: India-napolis
Status: offline

 
RE: passing the ID in response.redirect - 9/19/2005 11:28:01   
quote:

if session("Uname")<>"" then
response.redirect ("found.asp?ID=<%=ID%>")
when you are executing that code, you are already inside <%...%> and so you cannot use the <%= shortcut ; you have to use response.write

_____________________________

Dan

(in reply to AllenD)
AllenD

 

Posts: 258
From: Dayton, OH, USA
Status: offline

 
RE: passing the ID in response.redirect - 9/19/2005 11:45:26   
So is it impossible for me to pass the ID of the record? On the next page that shows the information for the user, how am I going to pass the record ID so that I can display thier information?

(in reply to AllenD)
ou812

 

Posts: 1612
Joined: 1/5/2002
From: San Diego
Status: offline

 
RE: passing the ID in response.redirect - 9/19/2005 12:22:46   
This should do it for you:
response.redirect ("found.asp?ID=" & ID)



_____________________________

-brian

EnterpriseDB: Enterprise-class relational database management system
PostgreSQL: The world's most advanced open source database

(in reply to AllenD)
AllenD

 

Posts: 258
From: Dayton, OH, USA
Status: offline

 
RE: passing the ID in response.redirect - 9/19/2005 12:36:15   
Hmm, ok, I dont get an error, but for some reason the ID field is not pulling, I am doing this above:

SQL="select ID,memberlogin,memberpassword from memberinfo where memberlogin='" & mememail & _
"' and memberpassword='" & mempassword & "'"
response.write SQL
response.write ID

I can see the SQL query, but the ID field is not showing...I can see the ID field in the database...

The code you gave me shows ID= on the URL line of the following page, but it is blank....Not sure why the ID field is not showing?

(in reply to ou812)
ou812

 

Posts: 1612
Joined: 1/5/2002
From: San Diego
Status: offline

 
RE: passing the ID in response.redirect - 9/19/2005 12:46:31   
You need to "grab" the data from query you just performed.

Depending on what variable name you used in opening your DB for querying (something like:
Set objRS = Server.CreateObject("ADODB.Recordset")
objRS.Open sql, DB_CONNECTIONSTRING, adOpenKeyset, adLockPessimistic)

will enforce what your statement looks like to get the data.

To get the actual data, and use it, you will need to get it doing something like this:
ID = objRS.fields("ID")


Same thing too, if you want to get the data for the other fields you queried:
mem_login = objRS.fields("memberlogin")
mem_password = objRS.fields("memberpassword")


< Message edited by ou812 -- 9/19/2005 12:52:47 >


_____________________________

-brian

EnterpriseDB: Enterprise-class relational database management system
PostgreSQL: The world's most advanced open source database

(in reply to AllenD)
AllenD

 

Posts: 258
From: Dayton, OH, USA
Status: offline

 
RE: passing the ID in response.redirect - 9/19/2005 12:55:07   
Ok, I understand the concept, but am lost on the exact statement...here is my complete code, I have the response.end for now to see if the ID field is correct...The following line is what I am stuck on: ID = objRS.ID("ID")

<%
Response.buffer=true
session("Uname")=""
mememail=request("memberlogin")
mempassword=request("memberpassword")
'response.write mememail
'response.write mempassword
'response.end
if mememail<>"" and mempassword <> "" then
Set Conn = Server.CreateObject("ADODB.Connection")
dsn="Provider=Microsoft.Jet.OLEDB.4.0;Data Source="& Server.MapPath("/fpdb/members.mdb")
Conn.Open dsn
Set RS = Server.CreateObject("ADODB.Recordset")
SQL="select ID,memberlogin,memberpassword from memberinfo where memberlogin='" & mememail & _
"' and memberpassword='" & mempassword & "'"
response.write SQL
ID = objRS.ID("ID")
response.write ID
response.end
Rs.Open sql,Conn,1,3
If NOT Rs.EOF then
session("Uname")=rs(0)
End If
Rs.Close
Conn.Close
end if
if session("Uname")<>"" then

response.redirect ("found.asp?ID=" & ID)
else
response.redirect ("notfound.asp")
end if
%>
<%'session("callfrom")=request("found.asp")
'if session("Uname")="" then response.redirect("notfound.asp")%>

(in reply to ou812)
ou812

 

Posts: 1612
Joined: 1/5/2002
From: San Diego
Status: offline

 
RE: passing the ID in response.redirect - 9/19/2005 13:17:34   
Change this:
quote:

ID = objRS.ID("ID")

to this:
ID = RS.fields("ID")


ALSO, you need to place this(and your response.write/end) AFTER this line: "Rs.Open sql,Conn,1,3 " This is where it executes your query.

Your object is "RS", and to grab the ID row data from your query you use "fields" in the object "RS"

_____________________________

-brian

EnterpriseDB: Enterprise-class relational database management system
PostgreSQL: The world's most advanced open source database

(in reply to AllenD)
AllenD

 

Posts: 258
From: Dayton, OH, USA
Status: offline

 
RE: passing the ID in response.redirect - 9/19/2005 13:27:25   
Ok, that makes sense. Thanks for all the help Brian, it works now! :)

(in reply to ou812)
ou812

 

Posts: 1612
Joined: 1/5/2002
From: San Diego
Status: offline

 
RE: passing the ID in response.redirect - 9/19/2005 13:28:06   
Great, glad you got it working!

_____________________________

-brian

EnterpriseDB: Enterprise-class relational database management system
PostgreSQL: The world's most advanced open source database

(in reply to AllenD)
AllenD

 

Posts: 258
From: Dayton, OH, USA
Status: offline

 
RE: passing the ID in response.redirect - 9/19/2005 14:05:38   
One more question <g>

On my next page I am getting the ID and writing out several fields, instead of doing this:

ufirstname = RS.fields("ufirstname")

For quite a few fields, is there a way to "globally" name all of them using the rs.fields?

In other words, I dont want to have to re-define every field over again if possible?

(in reply to ou812)
ou812

 

Posts: 1612
Joined: 1/5/2002
From: San Diego
Status: offline

 
RE: passing the ID in response.redirect - 9/19/2005 14:42:47   
I'm not quite sure I understand...

In a query, for whatever columns you want returned, and need to use, you should set it to a variable, which is used in the code for that page. So if you need three columns from a query, you should set three variables. RS.fields can be used with numbers instead of the column names, but I don't believe that will help much (ie. ID = RS.fields(1) , if it is the first column in the query ).

When the query is executed, the object RS is used to hold that data. You then need to either use the data as RS.field("somename") and leave the object open(NOT Recommended!) until you have done what is needed with the data OR store the needed data in variables (Recommended) and use those variables as needed. You don't really want to leave the recordset open any longer than needed to get the data (of course, sometimes there are good reasons to leave it open).

So, it isn't really (but kind of is) redefining variables, but being able to close out the recordset and still use the data.

_____________________________

-brian

EnterpriseDB: Enterprise-class relational database management system
PostgreSQL: The world's most advanced open source database

(in reply to AllenD)
AllenD

 

Posts: 258
From: Dayton, OH, USA
Status: offline

 
RE: passing the ID in response.redirect - 9/19/2005 14:48:30   
Ok, I was just trying to find a better way to somehow define all fields as they are in the database columns instead of doing this:

ufirstname = RS.fields("ufirstname")
ulastname = RS.fields("ulastname")
memberemail = RS.fields("memberemail")

-----
For example when using the FP Database results, I dont have to do the above, all fields are already there and I can just write them, without having to "re-define" them again?

So I kind of need to do like a wildcard (I know the below doesnt work, its just an example). Because I have maybe 15 fields, and I dont want to have to predefine them 15 times if I dont have too.

* = RS.fields("*")

(in reply to ou812)
ou812

 

Posts: 1612
Joined: 1/5/2002
From: San Diego
Status: offline

 
RE: passing the ID in response.redirect - 9/19/2005 14:58:45   
I've not used the FP database results, but I would guess it must be either keeping it open, or probably naming them for you in the asa file??? Another way, would be to store them in an array, by going through a loop to get all the names, but then your variables wouldn't have meaningful names.

Something like this?
for i = 1 to RS.fields.count
column(i) = RS.fields.(i)
next

Again though, I don't think I would go this route because it would be too hard to follow the code/variables for the columns. Of course, there may be a way to do this and I've just not seen it before!

_____________________________

-brian

EnterpriseDB: Enterprise-class relational database management system
PostgreSQL: The world's most advanced open source database

(in reply to AllenD)
AllenD

 

Posts: 258
From: Dayton, OH, USA
Status: offline

 
RE: passing the ID in response.redirect - 9/19/2005 16:20:59   
Ok, thanks for all the replies Brian, you have been most helpful ! :)

(in reply to ou812)
Page:   [1]
OutFront Discoveries

All Forums >> Web Development >> General Web Development >> passing the ID in response.redirect
Page: [1]
Jump to: 1





New Messages No New Messages
Hot Topic w/ New Messages Hot Topic w/o New Messages
Locked w/ New Messages Locked w/o New Messages
 Post New Thread
 Reply to Message
 Post New Poll
 Submit Vote
 Delete My Own Post
 Delete My Own Thread
 Rate Posts