ASP Programming
 
Forums: » Register « |  User CP |  Games |  Calendar |  Members |  FAQs |  Sitemap |  Support | 
User Name:
Password:
Remember me
Go Back   Dev Shed ForumsProgramming Languages - MoreASP Programming

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 Dev Shed Forums Sponsor:
  #1  
Old July 24th, 2003, 05:30 AM
colonel_klink colonel_klink is offline
Junior Member
Dev Shed Newbie (0 - 499 posts)
 
Join Date: Jun 2003
Posts: 12 colonel_klink User rank is Just a Lowly Private (1 - 20 Reputation Level) 
Time spent in forums: < 1 sec
Reputation Power: 0
Angry Accessing Querystring variable from SQL query ???

Hey all,

this is my script:

<html>
<head>
<title>Untitled Document</title>
<meta http-equiv="Content-Type" content="text/html; charset=iso-8859-1">
</head>

<body>
<%
Dim Connect, GBRS, Query

Set Connect = Server.CreateObject("ADODB.Connection")
Connect.Open "Provider=SQLOLEDB; Data Source=localhost; Initial Catalog=DBTEST; User ID=admin; Password=admin"
Set GBRS = Server.CreateObject("ADODB.Recordset")
Query = "SELECT * FROM Dcweb WHERE Id = Request.QueryString('msgid')"
GBRS.Open Query, Connect, adOpenStatic, 1
%>

Author = <%=GBRS("Aauthor")%>

</body>
</html>

See I am passing a variable through the URL www.myhost.com/acc.asp?msgid=whatever

I am now trying to access the row within the database that contains ONLY THAT ID.

I have a page with guesbook messages... and have the URL formatted so that it displays the ID within the link, so when the link is clicked the message id can be passed along so this page knows what to display. I am obviously going about it the wrong way, but I cannot seem to figure out another way to do it, prolly cause its 4am... but any help would be appriciated!!!! should I just do a select from all, and then somhow run a search on the Dbase??? uhhg.. lettme know I am still a noob I guess...

Thanks again,

Chris

Last edited by colonel_klink : July 24th, 2003 at 05:33 AM.

Reply With Quote
  #2  
Old July 24th, 2003, 07:40 AM
Vlince Vlince is offline
Contributing User
Dev Shed Newbie (0 - 499 posts)
 
Join Date: Jun 2003
Location: Canada, Quebec, Montreal
Posts: 410 Vlince User rank is Just a Lowly Private (1 - 20 Reputation Level) 
Time spent in forums: < 1 sec
Reputation Power: 6
What you need to do is debug your code, one good practice I use is to Response.Write my SQL Query *BEFORE* I execute it.

Now do something like:

<%
. . .
. .
.
Query = "SELECT * FROM Dcweb WHERE Id = Request.QueryString('msgid')"

'FOR DEBUG ONLY
'Response.Write "-->" & Query & "<--<hr>"
'Response.End


GBRS.Open Query, Connect, adOpenStatic, 1
. . .
. .
.
%>

Another thing...I'll assume your field Id is a numeric field so what you'll need to do is:

<%
. . .
. .
.
Dim lngUniqueId
lngUniqueId = Trim(Request.QueryString("msgid"))

If lngUniqueId = "" Then
Response.Write "The Id cannot be empty"
Response.End 'or Response.Redirect
End If

Query = "SELECT * FROM Dcweb WHERE Id = " & Clng(lngUniqueId)


'FOR DEBUG ONLY
'Response.Write "-->" & Query & "<--<hr>"
'Response.End


GBRS.Open Query, Connect, adOpenStatic, 1
. . .
. .
.
%>

I've put the QueryString value inside a variable called lngUniqueId
I've then made a simple validation on that variable cause if it holds nothing then your Query will crash!!!

Then I've used the Clng() on the variable to convert it into a long/number because Request.QueryString *always* return a string but since your field Id is numeric then you'll need to convert that string into a numeric value.


Hope this helps!
Sincerely

Vlince

Reply With Quote
  #3  
Old July 24th, 2003, 06:40 PM
colonel_klink colonel_klink is offline
Junior Member
Dev Shed Newbie (0 - 499 posts)
 
Join Date: Jun 2003
Posts: 12 colonel_klink User rank is Just a Lowly Private (1 - 20 Reputation Level) 
Time spent in forums: < 1 sec
Reputation Power: 0
Thanks so much, works perfect now!

Chris

Reply With Quote
Reply

Viewing: Dev Shed ForumsProgramming Languages - MoreASP Programming > Accessing Querystring variable from SQL query ???


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