|
|
|||||||||
|
|||||||||
| |||||||||
|
|
|
| |||||||||
![]() |
|
|
«
Previous Thread
|
Next Thread
»
|
Thread Tools | Search this Thread | Rate Thread | Display Modes |
|
#1
|
|||
|
|||
|
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. |
|
#2
|
|||
|
|||
|
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 |
|
#3
|
|||
|
|||
|
Thanks so much, works perfect now!
Chris |
![]() |
| Viewing: Dev Shed Forums > Programming Languages - More > ASP Programming > Accessing Querystring variable from SQL query ??? |
| Thread Tools | Search this Thread |
| Display Modes | Rate This Thread |
|
|
|
|