Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations sizbut on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

ASP url Variable to insert database

Status
Not open for further replies.

Dhagaxtuur

Technical User
Apr 15, 2003
47
CA
Problem:
I have saving value of a variable passed by url
<a href=&quot;message.asp?id=<%=RS(&quot;messageID&quot;)>&quot;>Add</a>. I want insert this variable to messageID field in a database. MessageID has number value and I am saying in the requesting page:
RS.Fields(&quot;messageID&quot;)=Request(&quot;id&quot;)

It's inserting blank value. The url is appears like this /message.asp?id=1 and I am assuming id has value assigned but does not insert into the database.

Could anyone help me with this. I don't want use session variable since I already have two many of them.
Thanks
 
Hi,
I think this code should work for u if u are having the url appears like /message.asp?id=1 also check in your code whether u have any if or while condition were this particular RS.Fields(&quot;messageID&quot;)=Request(&quot;id&quot;) statement is not executed.

Cheers

Ganesh Bbau
 
I can see two different possible problems. First is that you don't need to use a recordset if you're just trying to update something, an executed command will work much better. I have a suspicion that there is something wrong with your update code, not your query string.

That said, let's assume for the moment that your update code works fine and that there's something wrong with your query string code. Do these two things:[ol][li]Be more specific in what request data you're asking for by using
Code:
Request.QueryString(&quot;id&quot;)
-- it never hurts and often helps -- and[li]Check to see if that really is the problem by Response.Writing out your
Code:
Request.QueryString(&quot;id&quot;)
-- if it shows the value you want then the problem is in the update code, otherwise there's something else weird going on.[/ol]
 
Ok this is the code. I think it should work but it doesn't. The problem is not the if statment, SaveMessage is true and blankError is handled but TRS(&quot;messageID&quot;)=QueryString(&quot;tmID&quot;) is inserting blank. tmID is passed through the url which appears like /addThread.asp?tmID=1.
I printed out the tmID and it prints the value but does not insert into the database field.

<%
Option Explicit
dim messageID, thread, picture, currDate, blankErrors, saveMessage, TRS, SQL
'messageID=Request.QueryString(&quot;tmID&quot;)
thread=Trim(Replace(Request.Form(&quot;thread&quot;),&quot;&quot;&quot;&quot;,&quot;&quot;&quot;&quot;&quot;&quot;))
picture=Trim(Replace(Request.Form(&quot;picture&quot;),&quot;&quot;&quot;&quot;,&quot;&quot;&quot;&quot;&quot;&quot;))
currDate=Date()
if session(&quot;user&quot;)=&quot;&quot; then
blankErrors=blankErrors & &quot;You are not registered user, please <a href='register.asp'> register</a> or <a href='default.asp'>login</a><br>&quot;
end if
if len(thread)<6 or len(thread)>20000 then
blankErrors=blankErrors & &quot;Comment is two short or too long. 10-20,000 chars required. <br>&quot;
end if
saveMessage=Request.Form(&quot;Post&quot;)=&quot;Save&quot;
%>
<!-- #include file=connect.inc -->
<%
If saveMessage Then
if blankErrors=&quot;&quot; then
SQL = &quot;SELECT * FROM tblThreads&quot;
SET TRS= Server.CreateObject(&quot;ADODB.Recordset&quot;)
TRS.CursorType = 2
TRS.LockType = 3
TRS.Open SQL,Conn
TRS.AddNew
TRS.Fields(&quot;userName&quot;) = session(&quot;user&quot;)
TRS.Fields(&quot;messageID&quot;)=Request.QueryString(&quot;tmID&quot;)
TRS.Fields(&quot;thread&quot;)=thread
TRS.Fields(&quot;picture&quot;)=picture
TRS.Fields(&quot;datePosted&quot;)=currDate
TRS.update
Response.Write(&quot;Message ID&quot; & messageID)
'Response.Redirect(&quot;viewMessages.asp?mID=messageID&quot;)
Response.Write(&quot;Message ID&quot; & messageID)
end if
end if
%>

============================= This is the form part ======
<html>
<head>
<title>Post Message</title>
</head>
<BODY bgcolor=&quot;#FFFFCC&quot;&quot; text=&quot;#ffffff&quot; link=&quot;#0000ff&quot; vlink=&quot;#0000ff&quot; marginwidth=&quot;0&quot; marginheight=&quot;0&quot; leftmargin=&quot;0&quot; topmargin=&quot;0&quot;>
<!--#include virtual=&quot;/cliktoprogram/header.asp&quot;-->
<Table width=&quot;100%&quot; border=&quot;1&quot; cellspacing=&quot;0&quot; cellpadding=&quot;0&quot; bgcolor=&quot;#ffffcc&quot;>
<TR>
<TD width=&quot;30%&quot; valign=&quot;top&quot; align=&quot;left&quot; bgcolor=&quot;#ccccff&quot;>
<%if session(&quot;user&quot;)=&quot;&quot; then%>
<!--#include file=&quot;login.asp&quot;-->
<%else%>
<!--#include file=&quot;logged.asp&quot;-->
<%end if%>
<!--#include virtual=&quot;/cliktoprogram/right.asp&quot;-->
</TD>
<TD WIDTH=&quot;70%&quot; valign=&quot;top&quot; >
<%

if saveMessage and blankErrors<>&quot;&quot; then
Response.Write(&quot;<center>&quot;&&quot;<font color='red'>&quot;&blankErrors&&quot;</font>&quot;&&quot;</center>&quot;)
end if
if session(&quot;user&quot;)=&quot;&quot; then
Response.Write(&quot;<center><font color='red'>You must be a registered user in order to post a message</font></center>&quot;)
elseif messageID=&quot;&quot; then
Response.Write(&quot;<center><font color='red'>You must select a topic to reply to in order to post a message</font></center>&quot;)
else
%>

<form name=&quot;form1&quot; action=&quot;<%=Request.ServerVariables(&quot;URL&quot;)%>&quot; method=&quot;post&quot;>
<table border=.1 bordercolor=&quot;#000000&quot; bgcolor=&quot;ccccff&quot; width=&quot;100%&quot;>
<tr><td>Reply Message:</td></tr>
<tr><td><textarea name=&quot;thread&quot; cols=&quot;45&quot; rows=&quot;20&quot;><%=thread%></textarea></td></tr>
<tr><td>Picture:</td></tr>
<tr><td> <input TYPE=&quot;radio&quot; NAME=&quot;picture&quot; VALUE=&quot;images/1.gif&quot;><img src=&quot;images/1.gif&quot;>
<input TYPE=&quot;radio&quot; NAME=&quot;picture&quot; VALUE=&quot;images/2.gif&quot;><img src=&quot;images/2.gif&quot;>
<input TYPE=&quot;radio&quot; NAME=&quot;picture&quot; VALUE=&quot;images/3.gif&quot;><img src=&quot;images/3.gif&quot;>
<input TYPE=&quot;radio&quot; NAME=&quot;picture&quot; VALUE=&quot;images/4.gif&quot;><img src=&quot;images/4.gif&quot;>
<input TYPE=&quot;radio&quot; NAME=&quot;picture&quot; VALUE=&quot;images/5.gif&quot;><img src=&quot;images/5.gif&quot;>
<input TYPE=&quot;radio&quot; NAME=&quot;picture&quot; VALUE=&quot;images/6.gif&quot;><img src=&quot;images/6.gif&quot;></td></tr>
<tr><td><center> <input type=&quot;submit&quot; name=&quot;Post&quot; value=&quot;Save&quot;> <input type=&quot;reset&quot; name=&quot;reset&quot; value=&quot;Clear&quot;> </td></tr>
</table>
</form>
<% end if%>
</TD></TR>
</TABLE>
</BODY>
</HTML>

 
Hi ,
Can u confirm the following

1) The page name is addThread.asp
2) so first time when u browse this page the url will be addThread.asp and Request.ServerVariables(&quot;URL&quot;) will also be the same right?

So how this tmID=1 querystring is getting added to this URL?

 
The url to get to this page is <a href=&quot;addThread.asp?id=<%=RS(&quot;tmID&quot;)>&quot;>. I am using only one page (addThread.asp) -- the code you see is in one page.
 
It looks like action=&quot;<%=Request.ServerVariables(&quot;URL&quot;)%>&quot; is clearing out the tmID. Therefore, when save button is clicked. The url is reset to addThread.asp and the variable is not there anymore. The question is now, how do I contain the variable with action=&quot;<%=Request.ServerVariables(&quot;URL&quot;)%>&quot; on the second request when the save button is clicked?.

Thank Guys
 
Hi,
that was my question too in my earlier post..

this will not work the way u r looking at because if u use method=&quot;post&quot; in form tag it will not send values in query string.

so u have to use hidden input tag and store the message ID and then get it using request.form(&quot;hiddenmsgid&quot;)..

hope this helps..
 
Yes, I started doing the otherway (two seperate pages) thank you guys: vganeshbabu & Genimuse. I appreciate your help.
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top