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 Chris Miller on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

Request problem

Status
Not open for further replies.

enak

Programmer
Jul 2, 2002
412
US
I have a simple page where I am trying to get a value from a textbox after I have submitted the form but request does not work.

Here is my code:

<%@ Language=VBScript %>
<HTML>
<HEAD>
<META NAME=&quot;GENERATOR&quot; Content=&quot;Microsoft Visual Studio 6.0&quot;>
<script language=jscript>
function getUserName() {
var oNet, cInitial, startTime, sSQL;
oNet = new ActiveXObject(&quot;WScript.Network&quot;);
// Get the user name.
sUser = oNet.UserName;

frmMain.UserID.value=sUser;
}

function go(){
getUserName();
//frmMain.submit();
}

</script>

</HEAD>
<BODY onload=&quot;go();&quot;>

<form name=frmMain method=post action=&quot;index.asp&quot;>

<%
if Request(&quot;UserID&quot;) <> &quot;&quot; then
set cView = server.CreateObject(&quot;BPCaseMgmnt.cCaseView&quot;)
Set rs = Server.CreateObject(&quot;ADODB.Recordset&quot;)

querystring = &quot;select * from UserAllRightsList where AllRights = '&quot; & request(&quot;UserID&quot;) & &quot;'&quot;

if cView.getDataForTreeView(rs, queryString, strErr) then
session(&quot;Privilege&quot;) = IIF((rs(&quot;Settlement&quot;) = True or rs(&quot;Billing&quot;) = true), &quot;admin&quot;, &quot;user&quot;)
else
session(&quot;Privilege&quot;) = &quot;user&quot;
end if
rs.Close

' Response.Redirect &quot;Navigate.html&quot;
end if

%>

<table width=&quot;80%&quot;>
<tr><td><a href=&quot;index.asp&quot; onclick=&quot;frmMain.submit();&quot;>BP</a>
<tr><td><input type=text name=UserID></tr>
</table>

</form>

</BODY>
</HTML>
 
Where you have got in your code:

if Request(&quot;UserID&quot;)

change this to :

if Request.Form(&quot;UserID&quot;)
 
Thanks for your response. I tried that but still do not get the data from the previous page.
 
Apologies, I should have said that you also need to change you querystring from:

querystring = &quot;select * from UserAllRightsList where AllRights = '&quot; & request(&quot;UserID&quot;) & &quot;'&quot;

to

querystring = &quot;select * from UserAllRightsList where AllRights = '&quot; & request.form(&quot;UserID&quot;) & &quot;'&quot;
 
That isn't actually necessary, this question probably belonged in the ASP forum, but:
If you just use Request then it will check the Request.Form collection, Rquest.QueryString collection, session variable collection, and cookie collection for the variable. That shouldn't be the problem, although it is cleaner and more efficient to use Request.Form.

You may want to ty and print out that querystring without executing the rest of the code, to make sure your value is getting passed correctly (I suspect it is):
add:
Response.Write Request.Form(&quot;UserID&quot;)
Response.Write querystring
Response.End

right after you set the querystring to make sure the value is being passed correctly.

Second, if you haven't declared the IIF function that may be your problem, if I recall correctly this function is not built in for VBScript so you have to declare it yourself. Try replacing it with a simple If Else End If structure.

Third, check the strErr being returned from your getDataForTreeView. If an error is occurring then you are attempting to execute code without checking for it first.

Fourth, dependant on how many records are being returned, and how the tree view method is handling your recordset, you may be getting either an empty recordset (EOF and BOF is true) or it may be that the tree is returning the recordset to you after it has looped through it, meaning the recordset pointer could be pointing at the EOF if the tree view method didn't .MoveFirst it before returning it to you.

Fifth, depending on your database, it may be doing the SQL statement as a case sensitive equality check. You may want to try this:
querystring = &quot;select * from UserAllRightsList where AllRights LIKE '%&quot; & request(&quot;UserID&quot;) & &quot;'%&quot;

also in all cases where you are entering user input directly into a SQL statement you should always check that there aren't certain characters in it like a single quote or a percent sign, than can cause problems at the database end:
Code:
Dim UserId
UserId = Request.Form(&quot;UserID&quot;)
UserId = Replace(UserId,&quot;'&quot;,&quot;''&quot;)  'double single quotes is escape character for single quote in most db's
UserId = Replace(UserId,&quot;%&quot;,&quot;\%&quot;
querystring = &quot;select * from UserAllRightsList where AllRights LIKE '%&quot; & request(&quot;UserID&quot;) & &quot;'% {escape '\'}&quot;   'note this is MS SQServer type escape, probably differant depending on your db

Anyways, hopefully one of those should clear it up for you,
-Tarwn --- --- --- --- --- --- --- --- --- --- --- --- --- --- --- --- --- ---
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top