Wrox Programmer Forums
| Search | Today's Posts | Mark Forums Read
Classic ASP Basics For beginner programmers starting with "classic" ASP 3, pre-".NET." NOT for ASP.NET 1.0, 1.1, or 2.0
Welcome to the p2p.wrox.com Forums.

You are currently viewing the Classic ASP Basics section of the Wrox Programmer to Programmer discussions. This is a community of software programmers and website developers including Wrox book authors and readers. New member registration was closed in 2019. New posts were shut off and the site was archived into this static format as of October 1, 2020. If you require technical support for a Wrox book please contact http://hub.wiley.com
  #1 (permalink)  
Old July 29th, 2003, 04:59 PM
Authorized User
 
Join Date: Jun 2003
Location: Gulfport, Ms, USA.
Posts: 78
Thanks: 0
Thanked 0 Times in 0 Posts
Send a message via Yahoo to hcweb
Default Querystrings and Redirects

Hello all..
I'm trying to retrieve the id from a recordset below and insert it into the querystring for the redirect. Can anyone tell me the correct syntax to accomplish this? Below is some code as an example.

<% Response.Buffer TRUE %>
<%
  Option Explicit
  Dim strConnect
%>

<!-- METADATA TYPE="typelib"
              FILE="c:\program files\common files\system\ado\msado15.dll" -->
<%
  Dim objRS, objComm, strPrecNo
  strPrecNo = Request.Querystring("precinct")

  If strPrecNo = "False" Then
    Response.Write " Error in file "
  End IF

  Set objComm = Server.CreateObject("ADODB.Command")
  objComm.ActiveConnection = strConnect
  objComm.CommandText = "SELECT id from FILES WHERE tab_precinct_no = '" & strPrecNo & "' "

  objComm.CommandType = adCmdText
  Set objRS = objComm.Execute
  Set objComm = Nothing

  If objRS.EOF Then
    Response.Write "<b>File Not Found</b>"

  Else
    Response.Redirect "file.asp?id=" & objRS("id")
  End IF

  objRS.Close
  Set objRS = Nothing
  'Set objConn = Nothing
%>

Any help would be greatly appreciated!
  #2 (permalink)  
Old July 30th, 2003, 01:00 AM
Authorized User
 
Join Date: Jul 2003
Location: Athens, , Greece.
Posts: 50
Thanks: 0
Thanked 0 Times in 0 Posts
Default

Using your code I would suggest this. The difference is that you wont have a message if no record is returned.Let me know if it suits you :)

Cheers
Kostas

Code:
Dim objRS, strPrecNo
  strPrecNo = Request.Querystring("precinct")
  strSQL="SELECT id from FILES WHERE tab_precinct_no = '" & strPrecNo & "' "


  If strPrecNo = "False" Then
    Response.Write " Error in file "
  End IF
  Set objRs=Server.CreateObject("ADODB.RecordSet")
  objRs.Open strSQL, objConn

  'Do this if there is a record returned
  While Not objRS.EOF and objRs.BOF
    Response.Redirect "file.asp?id=" & objRS("id")
  Wend

  objRS.Close
  Set objRS = Nothing  
  'Set objConn = Nothing
  #3 (permalink)  
Old July 30th, 2003, 01:10 AM
Friend of Wrox
Points: 2,376, Level: 20
Points: 2,376, Level: 20 Points: 2,376, Level: 20 Points: 2,376, Level: 20
Activity: 0%
Activity: 0% Activity: 0% Activity: 0%
 
Join Date: Jun 2003
Location: , , Australia.
Posts: 596
Thanks: 1
Thanked 3 Times in 3 Posts
Default

hcweb,
I am not sure if this is a problem with your code or not but I highly recommend not using key words such as "id" for your tables field names.
This includes names such as "date","Length" and any other key words.
I try to avoid key words from VBScript or Javascript as well as SQL for clarity.
FileID would be better.

Rod

======================================
They say, best men are moulded out of faults,
And, for the most, become much more the better
For being a little bad.
======================================
  #4 (permalink)  
Old July 30th, 2003, 08:50 AM
Authorized User
 
Join Date: Jun 2003
Location: Gulfport, Ms, USA.
Posts: 78
Thanks: 0
Thanked 0 Times in 0 Posts
Send a message via Yahoo to hcweb
Default

Thanks for the responses guys! After fooling around with it this morning, it started working. Not sure exactly what changed or why it started working though.

The problem I was having was in the code below:

  Else
    Response.Redirect "file.asp?id=" & objRS("id")
  End IF

For some reason, this would just error out with an internal server error 500. I thought I may have had the syntax wrong in creating the querystring because of the error, but reviewing my code again, it's still the same. Nothing else has changed codewise, so I'm unsure of what exactly has happened.


Similar Threads
Thread Thread Starter Forum Replies Last Post
Session Management / Security / Redirects justinhume Beginning PHP 5 March 3rd, 2004 08:43 PM
querystrings in chapter 8 LL BOOK: Beginning PHP4/PHP 5 ISBN: 978-0-7645-4364-7; v5 ISBN: 978-0-7645-5783-5 2 November 19th, 2003 10:36 AM
Redirects skicrud Beginning PHP 1 October 10th, 2003 12:50 PM
HTTP_REFERER Tester Sometimes Redirects OK Visitor markw707 Classic ASP Basics 4 August 21st, 2003 11:41 PM
Querystrings to Variables hcweb Classic ASP Basics 1 June 14th, 2003 06:54 PM





Powered by vBulletin®
Copyright ©2000 - 2020, Jelsoft Enterprises Ltd.
Copyright (c) 2020 John Wiley & Sons, Inc.