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

Returning a value when statement is true SQL and ASP

Status
Not open for further replies.

UnfitElf

Programmer
Dec 3, 2002
24
NZ
Hi all..
First i would just like to say im a beginner at all this SQL stuff... BUT, i have a small prob. I am creating a login page in asp but am using a database so thats were the SQL come in. I need it to search the database and return the value 1 if the username is equal to the username in the database, and if the password is equal to the password from the database. I am getting the username and password of a form i have created.

The section of code i an having problems with is this:

<%
sSQL = &quot;select 1 from users where username = '&quot; & request(&quot;Username&quot;) & &quot;' and password = '&quot; & request(&quot;Password&quot;) & &quot;'&quot;

Set oConn = Server.CreateObject(&quot;ADODB.Connection&quot;)
oConn.Open &quot;DSN=myDatabase&quot;
oConn.execute sSQL
oConn.Close
Set oConn = Nothing
response.write(sSQL)'This is to see if the value of sSQL is actually = &quot;1&quot;. Currently it is not as something is going wrong.
%>

How can i get the SQL to return the value 1 when the statement is true and make eighter the sSQL variable or any other variable equal to the one if the statement is true.

Thanks for any help :)
 
Checking userName and password in asp is easiest using the following method:

<%
sSQL = &quot;select * from users where username = '&quot; & request(&quot;Username&quot;) & &quot;' and password = '&quot; & request(&quot;Password&quot;) & &quot;'&quot;

Set oConn = Server.CreateObject(&quot;ADODB.Connection&quot;)
set oRS = Server.CreateObject(&quot;ADODB.recordset&quot;)
oConn.Open &quot;DSN=myDatabase&quot;
set oRS = oConn.execute(sSQL)
oConn.Close
Set oConn = Nothing

if not oRS.EOF then
'password & username work
else
'no match found
end if

%>
Get the Best Answers! faq333-2924
Merry Christmas!
mikewolf@tst-us.com
[angel][santa][elf][reindeer][santa2]
 
You can use the simple way as mwolf00 mentioned!

If you need the exact answer for question, use:

select count(id) from table where username = 'name' and password = 'password'

This query will return 1 if user exist or 0 if not!

P.S :> Query answer might be greater than 1 if you have same username and password twice.

so use :

if (query.result > 0 ) {
' user valid
} Sivakumar Kandaraj :)
System Administrator,Web Programmer
Melbourne
Australia.
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top