Update SELECT statement with form field? - Postet den (1764 Views)
Junior Member
Lon2
Innlegg: 151
151
Anyone know how to make an SQL SELECT statement updateable by a form field entry? For example:

Code:
rsTopics.Source = "SELECT * FROM Topics WHERE TopicID = 365"
I would like make the TopicID equals part (365) updateable by just typing the number in a form on an ASP page and clicking submit to update the page with the new TopicID number.<
   
 Sidestørrelse 
Postet den
Advanced Member
Etymon
Innlegg: 2396
2396
Originally posted by Lon2
Anyone know how to make an SQL SELECT statement updateable by a form field entry? For example:

Code:
rsTopics.Source = "SELECT * FROM Topics WHERE TopicID = 365"
I would like make the TopicID equals part (365) updateable by just typing the number in a form on an ASP page and clicking submit to update the page with the new TopicID number.

Take a look at post.asp and post_info.asp to see how they work together. What you are appearing to want done is to have your 365 become the catcher's mit for the form value like this TopicID = Request.Form("Topic_ID") ... so on post.asp look for a form value like name=""TOPIC_ID"" and then look on post_info.asp to see how that value is caught and processed (look for TopicID = " & cLng(Request.Form("Topic_ID")) & ").
Note, for a new topic, you will not see the topic_id value on the post.asp side because it has not been created yet, so look for name=""TOPIC_ID"" type=""hidden"" value=""" & strRqTopicID & """ where you find the name=""Method_Type"" type=""hidden"" value=""Reply"" or name=""Method_Type"" type=""hidden"" value=""EditReply"" or name=""Method_Type"" type=""hidden"" value=""EditTopic"" parts of the form on post.asp. That is where you will find the beginning of your question. How it is processed in post_info.asp is where you will find the answer to your question. smile<
Postet den
Advanced Member
Carefree
Innlegg: 4224
4224
You could also do it as a variable passed in a query expression. At the beginning of your "topic.asp", add this:

Code:

dim intTPID
intTPID=server.htmlencode(request.QueryString)

or, to use a simple variable from a form:

Code:

dim intTPID
intTPID=request.form("-----")

Note: You'll need to change the five hyphen "-" characters to the name of your form field representing the topic ID.
For both/either of the cases above, change your line of code to say:
Code:

rsTopics.Source = "SELECT * FROM " & strActivePrefix & "Topics WHERE Topic_ID = " & intTPID

Thanks to Etymon for the table/variable correction - don't know where my mind was.<
Postet den
Snitz Forums Admin
ruirib
Innlegg: 26364
26364
Carefree,

Better sanitize it too...<
Postet den
Junior Member
Lon2
Innlegg: 151
151
Thanks for the answers!
I did what Carefree suggested:
Code:
rsTopics.Source = "SELECT * FROM Topics WHERE TopicID =" & intTPID

and

dim intTPID
intTPID=request.form("ManualTopicID")

and

<form action="pend_topics.asp" method="post" name="ManualTopicID"><input type="text" size="10">
<input type="submit" name="Submit2" value="Submit">
</form>
And get the following error:

Syntax error (missing operator) in query expression 'TopicID ='.<
Postet den
Advanced Member
Etymon
Innlegg: 2396
2396
The field you are querying should be topic_id<
Postet den
Junior Member
Lon2
Innlegg: 151
151
I'm sorry I'm not following you, Etymon...
When I manually write this:
Code:
rsTopics.Source = "SELECT * FROM Topics WHERE TopicID = 365
and upload it to the server, the page works correctly and shows all responses to the topic. When I write this:
Code:
rsTopics.Source = "SELECT * FROM Topics WHERE TopicID =" & intTPID
With the seperate dim statement and form, I get the error listed aboved. What am I doing wrong?




<
Postet den
Advanced Member
Etymon
Innlegg: 2396
2396
Unless you have a table structure that is different from a standard Snitz FORUM_TOPICS table ...

rsTopics.Source = "SELECT * FROM Topics WHERE TopicID =" & intTPID

should be:

rsTopics.Source = "SELECT * FROM " & strActivePrefix & "Topics WHERE Topic_ID = " & intTPID

or:

rsTopics.Source = "SELECT * FROM FORUM_Topics WHERE Topic_ID = " & intTPID<
Postet den
Advanced Member
Etymon
Innlegg: 2396
2396
Are you trying to make it so that folks can search for a Topic ID from a form?<
Postet den
Junior Member
Lon2
Innlegg: 151
151
Sorry but this doesn't have anything to do with Snitz forums or Snitz code, hence the reason I started this topic in the "Code Support: ASP (Non-Forum Related)" forum. I was just using examples similar to Snitz in hopes it would be easier understood. Sorry for the confusion! smile
I should also clarify that the form, where the TopicID (365) is entered, is not accessible to anyone on the site. It is on an ASP page with a login for my access only.
Hope this doesn't discourage anyone from helping me further. I'm still stumped.<
Postet den
Advanced Member
Carefree
Innlegg: 4224
4224
Then we're back to ALMOST where we started.
Using a variable from a form:

Code:

dim intTPID
intTPID=request.form("-----")

Note: You'll need to change the five hyphen "-" characters to the name of your form field representing the topic ID.
Change your line of code to say:
Code:

rsTopics.Source = "SELECT * FROM Topics WHERE TopicID = " & intTPID

This should work. Your error is in using the FORM's name instead of the FIELD's name.<
Du må legge inn en melding