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

loop through access DB to find record

Status
Not open for further replies.

Dashsa

Programmer
Aug 7, 2006
110
US
Hello,
I am making a simple login that will loop through an access DB an check to see if the email address(username) is listed and act accordingly.
here is the code I have so far.
Code:
<%@ language=JScript %>
<!-- #include file="adojavas.inc" -->
<html>
<head>

</head>

<body>
	<%
var userEmail = Request.Form("uemail")
var userPass=Request.Form("upass")

var connect = Server.CreateObject("ADODB.Connection");
	var record = Server.CreateObject("ADODB.RecordSet");
	connect.Open("DSN=hhhba");
	record.Open("select * from TestData where EmailAddress  ='"+ userEmail+"'", connect, adOpenKeyset, adLockOptimistic);

	var testEmail = record("EmailAddress");

if (testEmail == userEmail )
{
Response.Write("Already Used!")
}
else
{
Response.Write("PASS!!")
}
	connect.close();
	connect = null;

%>
	
	</body></html>

it is not looping do you have any suggestions on this?

Thanks
 
your code is all over the place...

Here are the steps:

1. Query the db for the requested username, as you have done.

2. Check to see if a record exists (i.e. NOT RS.EOF) if you are at the end of the record set as soon as you execute the query, the username does not exists, if you are not at the end, it does exist.

Here is some code in VBSCRIPT, see you if you make sense of it and appy it:

Code:
username = request.form("tbxUserName")
sql = "select * from myTable where username = '" & username
set rs = myConn.execute(sql)
  if rs.eof and rs.bof then
    isUsed = false
  else
    isUsed = true
  end if
  rs.close
set rs = nothing

--------
GOOGLE is a great resource to find answers to questions like "how do i..."

If you don't know exaclty what you want to do or what to search on, try Google Suggest: --------
I have recently been semi-converted to ensuring all my code (well most of it) works in both javascript and non-javasc
 
Thanks
I modified you code a bit and came up with :
Code:
var connect = Server.CreateObject("ADODB.Connection");
	var record = Server.CreateObject("ADODB.RecordSet");
	connect.Open("DSN=hhhba");
	record.Open("select * from TestData where EmailAddress  ='"+ userEmail+"'", connect, adOpenKeyset, adLockOptimistic);
var isUsed;


	if(!record.EOF)
		{
		isUsed = true;
		 }
		 else
		 {
		 isUsed = false;
		 }
		 connect.close();
		 connect=null;
		 
		 Response.write(isUsed)
Response.write("if above is true name is used.")

It seems to be working at the moment.
Thanks again
 
Hello Kirby,
I guess thats the beauty of these forms -
They help people like me sort out my logic!
I really thought I had to loop through the DB but just looking for the location of the name makes more sense and works well!
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top