Forum Moderators: open

Message Too Old, No Replies

ASP Syntax Problem

Fitting a global variable into a query

         

brotherhood of LAN

7:46 pm on Aug 19, 2002 (gmt 0)

WebmasterWorld Senior Member 10+ Year Member Top Contributors Of The Month



I'm not too great with ASP, and most of what is produced is courtesy of Frontpage with a little tweaking in Notepad to stop the program abusing the code ;)

The prog is good for quickly getting some database results on the go...the query is run of the mill...a primary key equalling "whatever" to display the particular contents of the page.

The primary key will be the URL, since all pages will need a unique URL. I found out to acquire the URL I can use the below request

<%= Request.ServerVariables("URL") %>

Using this code simply prints it out, which is fine. But I want to put the contents of that variable in the HERE bit below

fp_sQry="SELECT * FROM table WHERE (id = 'HERE')"

Hopefully it will save some hassle over the long term, but I'm not sure of the syntax here....I know I simply can't copy and paste code bit #1 into the query....as it thinks all the code inside the single quotes is the WHERE statement.

Can an ASP wizard be so kind to correct me on the syntax to fit the funky variable into the query? :)

Thanks for the replies in advance!

evinrude

7:53 pm on Aug 19, 2002 (gmt 0)

10+ Year Member



try something along the lines of:

<%
myURL = Request.ServerVariables("URL")

fp_sQry = "SELECT * FROM table WHERE (id = '" & myURL & "')"
%>

or

<%
fp_sQry = "SELECT * FROM table WHERE (id = '" & Request.ServerVariables("URL") & "'")
%>

brotherhood of LAN

8:23 pm on Aug 19, 2002 (gmt 0)

WebmasterWorld Senior Member 10+ Year Member Top Contributors Of The Month



Thanks for the speedy reply evinrude ;)

I get a "page cannot be displayed" with the error "Expected end of statement" with both your methods.

I noticed by adding an extra comma after the id= bit- I managed to get the page displayed using your 2nd example, though I get this :

Syntax error (missing operator) in query expression '(id ='.

Just a little syntax error? :) I would not know any better....

/added
The whole statement is used in an included .asp page if that applies at all in the case of acquiring the URL here

smokin

8:31 pm on Aug 19, 2002 (gmt 0)

10+ Year Member



WHERE (id = '" & Request.ServerVariables("URL") & "'")

You could try without the brackets around the WHERE clause:

WHERE id = '" & Request.ServerVariables("URL") & "'"

brotherhood of LAN

8:33 pm on Aug 19, 2002 (gmt 0)

WebmasterWorld Senior Member 10+ Year Member Top Contributors Of The Month



That is it on the nail...it's beautiful when the page loads like it should ;)

Thanks to the both of ya, it's appreciated