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

Find record ASP

Status
Not open for further replies.

Phailak

Programmer
Apr 10, 2001
142
CA
Hail,

What would be the code to find a recordset as done here in regular VB code

rs.findfirst "Name = 'Patrick' "

Phailak
 
dim name
name = "Patrick"

rs.find "Name='" & name & "'"

:)

or just

SELECT top 1 FROM tableName WHERE Name='" & name & "'"


 
Thanx again Link9, you've been a real help lately,

if I show you my code, can you take a look and tell me if it looks ok, if you have time of course. My small problem is that when I load the page, the word Incorrect appears right away when I want it to appear, if need be, only after the cmdLogin button has been pushed:

<%@ Language=VBScript %>

<HTML>

<%
dim sql, conn, PWD, UID, EntPWD
Response.Write &quot;<form name=frmTT method=post action=default.asp>&quot;
%>

<head>
<title>Gladiators</title>
</head>

<body text=&quot;#000000&quot; bgcolor=&quot;#C0C0C0&quot; link=&quot;#0000EE&quot; vlink=&quot;#FFFF99&quot; alink=&quot;#FF0000&quot;>

<center><font size=+4>Gladiators</font><font size=+4></font>
<p><font size=+2>Your nostrils fill with the scent of blood and sweat.
Your eyes focus on your enemy's blade. Your ears rejoyce in your opponent's
screams of agony. Your mouth waters in anticipation of victory. The crowds.
The cheers. </font><font size=+3>VICTORY...</font><font size=+3></font>
<p><font size=+2>Your nostrils struggle to breathe. Your eyes are blinded
by the blood flowing from your brow. Your ears shy away from your
enemy's taunts. Your mouth fills with blood, drowning you in defeat. The
crowds. The cheers. </font><font size=+3>DEFEAT...</font><font size=+3></font>
<p><font size=+2>Be it one or the other, GLORY or SHAME, you ARE destined
to be a...</font><font size=+2></font>
<p><font size=+4>Gladiator</font><font size=+4></font>
<br>
<p><font size=+4>UserID:</font><font size=+4></font>
<br><br>
<div align=&quot;center&quot;><input type=&quot;text&quot; name=&quot;txtUserID&quot; value=&quot;&quot; size=&quot;15&quot; maxlength=&quot;15&quot;></div>
<br>
<p><font size=+4>Password:</font></center>
<br><br>
<div align=&quot;center&quot;><input type=&quot;text&quot; name=&quot;txtPassword&quot; value=&quot;&quot; size=&quot;15&quot; maxlength=&quot;15&quot;></div>
<br><br><br><br>

<%
if Request.Form(&quot;cmdLogin&quot;) <> &quot;&quot; then

UID = request.form(&quot;txtUserID&quot;)
EntPWD = request.form(&quot;txtPassword&quot;)
sql = &quot;select top 1 password, UserID from players Where UserID = '&quot; & UID & &quot;'&quot;
Set Conn = Server.CreateObject(&quot;ADODB.Connection&quot;)
Conn.Open &quot;Glad&quot;
Set rs = Server.CreateObject(&quot;ADODB.Recordset&quot;)
rs.Open sql, Conn

if not rs.EOF then
PWD = rs(&quot;Password&quot;)
if PWD = EntPWD then
Response.Write &quot;Correct&quot;
else
Response.Write &quot;Incorrect&quot;
end if
else
PWD = &quot;No such User&quot;
Response.Write PWD
end if

rs.Close
conn.Close
set conn = nothing
set rs = nothing

end if

Response.Write &quot;<div align=center><input type=submit name=cmdLogin value=Login></div><br><br>&quot;
Response.Write &quot;</body></form></html>&quot;
%>

if all this is not clear let me know

Phailak
 
hmmm... I don't think I get it...

This appears to be your login page, but you are checking the password and userID here on the same page --

I think that's where you are in error --

Try taking out the asp script that is here, and placing it on the page where your form is pointing to, 'default.asp' -- that way, a user visits this page, enters their info, and then they hit 'Login'...

the information is then sent to default.asp to run the password checking --

Then, you can redirect them to wherever they are supposed to go...

Is this making sense, or am I missing the point here?

:)
paul

 
Oh, ok I get it. So basically, because it would point elsewhere, that &quot;Incorrect&quot; word would not appear when I load the first page. Ok that makes sense. I'll try it and keep you posted on my progress, this is actually quite interesting this ASP stuff.

Thanx Again

Phailak
 
Hi,

Me again,

It works great, but let me see if I get this straight...
Each time I need to call an event (like a user clicking a button) I need to load a new page? And this is determined with the following line?

Response.Write &quot;<form name=frmTT method=post action=Login.asp>&quot;

So that when the user on the submit button it refers to that line where action redirects it to the other ASP script... am I ok so far.

What if it's a regular button instead of submit button, would it work in the same way? Or am I confusing two different things?

Once again, sorry for all the questions, but it's so much easier learning from people on forums than books and stuff

Trial and error I guess

Phailak
 
You are right on track. There is actually a way to make a round trip to the server and get info from a database without submitting a form, and it's called remote scripting, but it can get complicated, and is probably best left for another discussion...

As a rule, you are right on track as far as the submit button goes -- when a user clicks a Submit button, the data that is in the form elements is bundled up and whisked away to the page that you have specified in the action portion of your form...

Other buttons can be used -- you can call functions with them, if you wish -- and have them do something -- like maybe validate the contents of the form before you submit, and then the last line of your function could well be... document.formName.submit()

which, in essence, does the exact same thing as your user actually pressing a 'Submit' button...

:)
 
Ok, I think I understand most of it, but you can be sure I'll be back on here for more help. I'm not sure I get how to use other buttons, maybe you can give me a concrete example?
Anyway, thax again

Phailak
 
<input type=button value=&quot;Just a Button&quot; onClick=&quot;someFunction();&quot;>

<script>
function someFunction(){
document.formName.submit();
}
</script>

so you see you have effectively made that button a submit button, even though it isn't technically a submit button -- and so it stands to reason that you might want to do something else in that function besides just the submit, such as form validation, or anything else you need.

:)
 
Hail,

Thanx for the exemple, good stuff...
Another question if your infinite wisdom permits ;O)

Is there a way to implement a timer? Kind of like a vb timer...
If possible, how would the events be played, let's say...

After 1 minute of the user being on the page, a new window opens but the original page is not closed.
Then after 5 minutes, the same repeats and so forth every 5 minutes until the user presses a button or something...

Phailak
 
Well, I'm sure there is a way to do that with a session object or something, but that probably wouldn't be a good idea, and here's why --

It would have to be kept up with on the server -- a timer object -- it would be the only way to introduce a real timer into the equation.

So you have your timer object ticking away and say 5 visitors on your site ----> that equals five objects ticking away (spin looping = mucho server resources) -- but with only 5 visitors... eh... not too bad...

But lets say all of a sudden 500 other people (or worse, 5000) suddenly logon to the site, and ... I think you see where I'm going with this --

Your performance just took a SERIOUS nosedive, and if you're lucky, your server won't crash...

Setting session objects just isn't a good idea... variables are ok -- because they take up less real estate.

So how else could you do it??? I suppose you could continue checking system time -- set it to a client side variable when the page loads, and use the javascript setTimeout() function to keep track of what's going on --

Hey - there's an idea!

Ok -- back up --

javascript has a function called setTimeout that effectively works like a 'pause' function -- it doesn't wait on modal components to finish what they are doing (i.e. modal components won't 'pause' the 'pause' function -- if that makes any sense), but it works like this...

setTimeout('someJavascriptExpressionOrFunction', timeInMilliseconds)

So that once that line of code is encountered, it starts counting, and when the specified number of milliseconds has passed, it executes whatever is supposed to be executed. What's in quotes up there can either be a javaScript expression or a function call --

I bet if you played around with that method, you could get something to work for ya.

:)
Paul Prewett
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top