Subject: Help with login page creation
Posted By: neil.abachi07 Post Date: 2/16/2007 6:45:41 AM
Hi,
**FORGIVE ME AS THIS WAS POSTED IN ERROR ELSEWHERE**

I have been tasked into creating a login page for a website i am designing. I have never used asp before and therefore have little idea as to what i can do.
I have created a database in access and am using Macromedia Dreamweaver to create a page. I am lead to believe i want to create an asp page with a form that i then link to the database. This is where i get stuck - what happens next once the link is created etc? How can i test/view this as i know asp doesnt just render into IE or firefox.

I thank you in advance for your advice and information in aiding me with this.

Neil

Reply By: mike_remember Reply Date: 2/16/2007 7:02:17 AM
Hi

Though this is not an ASP section, still we can try to help you out, for your help, you can copy and past the below code in an asp page, I created this page years ago as a login for my application. Just change your access db path and the query to fetch username/password. (marked in red).

----------------------------------------------------------------------
<%
dim username, password
username=TRIM(Request("username"))
password=TRIM(Request("password"))

   Dim Con, sql, rec
   set Con = Server.CreateObject("ADODB.Connection")
  Con.Open "DRIVER={Microsoft Access Driver (*.mdb)}; DBQ=" & Server.MapPath("database.mdb")   
'Select the record matching the username.
   sql = "SELECT * FROM tblusers WHERE UCase(username)=' "& UCase(username) & "' AND UCase(password)=' " & UCase(password) & " ' "
   set rec=Con.execute(sql)
   'If no match found, EOF is not true.
   if NOT rec.EOF then
      Response.Redirect("somepage.asp") 'Change to page redirect to after login
   else
      blankError="Invalid username." 'EOF is true, no match found.
   end if

%>
<html>
    <head>
        <title>Login</title>
    </head>
    <body>
        <form name="productForm" method="post" ID="Form1">
            <center>
                <table border="1" ID="Table1">
                    <tr>
                        <td colspan="2">
                            <%

if blankError<>"" then
Response.Write("<center><font color='red' size='3'>"&blankError&"</font></center>")
end if
%>
                        </td>
                    </tr>
                    <tr>
                        <td><Strong><font face="courier new" size="3">Username:</font></Strong></td>
                        <td><input type="text" name="username" size="35" ID="Text1"></td>
                    </tr>
                    <tr>
                        <td><Strong><font face="courier new" size="3">Password</font></Strong></td>
                        <td><input type="password" name="password" size="35" ID="Password1"></td>
                    </tr>
                    <tr>
                        <td colspan="2" align="center"><input type="submit" name="loginButton" value="Login" ID="Submit1">
                            <input type="reset" name="reset" value="Clear" ID="Reset1"></td>
                    </tr>
                </table>
            </center>
        </form>
    </body>
</html>

----------------------------------------------------------------------

Regards
Mike

Fortune favours the brave, so don't regret on missed oppurtunities.
Reply By: neil.abachi07 Reply Date: 2/16/2007 7:57:27 AM
Hi Mike,

thanks for that, thats really appreciated. What i want to do is create a new ASP VBScript page and stick that code in there?
What happens, what do i do after that? do i have to create an HTML page calling the asp page? where do i load the asp page and how can i test?

Thanks again

Neil

Reply By: mike_remember Reply Date: 2/16/2007 8:54:42 AM
Well Neil

From your posts, what I could get is that you are basically a designer and have no idea of programming. I think you will need some practical help of a programmer at some stage. Anyways, I'll try to help you as much as possible.

To host asp pages, you will need IIS as webserver, wherein you will host your application. ASP pages can be created in plain notepad, and saved with .asp extension. I suggest that you copy and paste the content I posted, in a notepad file, save it as login.asp extension. Now create your application folder in the root folder of your machine, in (c:\inetput\wwwroot).

Now to test it, just enter this URL in your browser:
http://localhost/yourapplicationname/login.asp

Regards
Mike

Fortune favours the brave, so don't regret on missed oppurtunities.
Reply By: dparsons Reply Date: 2/16/2007 9:02:27 AM
To build upon Mikes statement a little bit more, if you are going to use Notepad that is inculuded with windows, when you go to save the file surround your file name with quotes in the Notepad save dialog so test.asp would be "test.asp".  If you do not do this, notepad may save our file as test.asp.txt, which is undesireable.

Secondly, I don't suggest using plain old notepad, although that is where I started writing ASP years ago I would suggest downloading PSPad or Notepad+ (both are freeware) and work wonderfully for these types of things.  (PSPad is a much better product IMHO)

hth

===========================================================
Read this if you want to know how to get a correct reply for your question:
http://www.catb.org/~esr/faqs/smart-questions.html
^^Took that from planoie's profile^^
^^Modified text taken from gbianchi profile^^
===========================================================
Technical Editor for: Professional Search Engine Optimization with ASP.NET
http://www.wiley.com/WileyCDA/WileyTitle/productCd-0470131470.html
Reply By: mike_remember Reply Date: 2/16/2007 9:07:36 AM
Yep Parsons

I too agree with your suggestions, I forgot to mention that while saving the notepad file, don't forget to select "All Files" option from the "Save as Type" dropdown (another alternate to what parsons suggested).

Secondly, I suggested to use notepad coz Neil seems to be really new to programming, else he could easily use a lot of editors as you mentioned parsons (well my choice would be Interdev)

Regards
Mike

Fortune favours the brave, so don't regret on missed oppurtunities.
Reply By: neil.abachi07 Reply Date: 2/16/2007 9:42:42 AM
Hi Guys,

Thanks for all the advice, really is kind of you!
I am a newbie when it comes to programming, i can do HTML and some CSS but beyond that i dont seem to have a natural aptitude for it.
I can use notepad as suggested or i can use dreamweaver that i know and love.
I have installed IIS as required but when i ran it it couldn't find anything in the c:\windows\system32\inetsrv\ folder, the folder is there but empty. i downloaded and re-sinstalled IIS 6.0 but still nothing.

Any ideas?

Neil

Reply By: mike_remember Reply Date: 2/16/2007 9:45:14 AM
what did u try to run, and what u couldn't find, please elaborate a bit, did u follow the steps that I suggested?

Regards
Mike

Fortune favours the brave, so don't regret on missed oppurtunities.
Reply By: dparsons Reply Date: 2/16/2007 9:54:59 AM
You run IIS's configuration manager by going to Start --> Settings --> Control Panel --> Administrative Tools --> Internet Information Services which opens up an MMC type console window that you can configure your website.  

Also, I have never downloaded IIS, I have always installed it from windows CD and if you are on XP Pro you should be using IIS 5.1 as it is what comes with the XP Pro CD.  (IIS 6.0 is what ships with Windows Server 2K3, 7.0 is Vista)

Also, if you are on XP HOME, I do not think you can install a webserver without some form of Hack.

===========================================================
Read this if you want to know how to get a correct reply for your question:
http://www.catb.org/~esr/faqs/smart-questions.html
^^Took that from planoie's profile^^
^^Modified text taken from gbianchi profile^^
===========================================================
Technical Editor for: Professional Search Engine Optimization with ASP.NET
http://www.wiley.com/WileyCDA/WileyTitle/productCd-0470131470.html
Reply By: neil.abachi07 Reply Date: 2/16/2007 10:16:16 AM
apologies - was my stupidity - i had home edition so i have done it on my work pc as i have just installed IIS and put the asp and the mdb files in the c:\inetpub\wwwroot
the next bit is somewhat confusing:

http://localhost/yourapplicationfolder/login.asp

 - how would that look if, for instance, you where going to look at yours?

Many thanks once more

Neil

Reply By: dparsons Reply Date: 2/16/2007 10:23:20 AM
do this:

Create a folder: C:\inetpub\wwwroot\<yourfolder>

Open up the IIS MMC as outlined in my previous post.

Expand the local computer node, then expand the Websites node, you will see some folders, in there the folder that you created will also be displayed.

Right click the folder, select properties, on the first tab it says application settings about a third of the way down click the create button on the right side of the tab.  Hit apply, hit ok.

Now, navigate to: http://localhost/<yourfoldername>/login.asp

===========================================================
Read this if you want to know how to get a correct reply for your question:
http://www.catb.org/~esr/faqs/smart-questions.html
^^Took that from planoie's profile^^
^^Modified text taken from gbianchi profile^^
===========================================================
Technical Editor for: Professional Search Engine Optimization with ASP.NET
http://www.wiley.com/WileyCDA/WileyTitle/productCd-0470131470.html
Reply By: neil.abachi07 Reply Date: 2/16/2007 10:36:57 AM
Thanks,

I have created, i have it set, is the local host the name of the pc im running it on or is it something else?

i have http://??????/Folder/login.asp

Neil

Reply By: neil.abachi07 Reply Date: 2/16/2007 10:55:41 AM
Again with the stupidity! I have the rest of the website working now but i cant get the login.asp to load.

I created it in notepad, changed the mdb file path and saved as login.asp as i was told

i then made a link through my website to go to that page and everytime it comes back with a page cannot be displayed error

Neil

Reply By: dparsons Reply Date: 2/16/2007 10:57:47 AM
your URL can be:

http://localhost/Folder/login.asp OR
http://<computername>/folder/login.asp

replace computername with the name of your computer.

===========================================================
Read this if you want to know how to get a correct reply for your question:
http://www.catb.org/~esr/faqs/smart-questions.html
^^Took that from planoie's profile^^
^^Modified text taken from gbianchi profile^^
===========================================================
Technical Editor for: Professional Search Engine Optimization with ASP.NET
http://www.wiley.com/WileyCDA/WileyTitle/productCd-0470131470.html
Reply By: neil.abachi07 Reply Date: 2/16/2007 11:09:00 AM
yeah, i got it working as http://localhost/<foldername>/<homepage>.html

login.asp will not load still, i appreciate all your help though

Neil

Reply By: dparsons Reply Date: 2/16/2007 11:29:23 AM
Are you getting a 500 Server error or a 404 Page not found error?

===========================================================
Read this if you want to know how to get a correct reply for your question:
http://www.catb.org/~esr/faqs/smart-questions.html
^^Took that from planoie's profile^^
^^Modified text taken from gbianchi profile^^
===========================================================
Technical Editor for: Professional Search Engine Optimization with ASP.NET
http://www.wiley.com/WileyCDA/WileyTitle/productCd-0470131470.html
Reply By: neil.abachi07 Reply Date: 2/16/2007 11:38:28 AM
This is exactly what it says:

HTTP 500.100 - Internal Server Error - ASP Error
Internet Information Services

Error type:
Server.MapPath(), ASP 0172 (0x80004005)
The path perameter for the MapPath method must be a virtual path. A physical path was used./<folder name>/login.asp, line 8

thanks

neil

Reply By: dparsons Reply Date: 2/16/2007 11:50:33 AM
Server.MapPath takes a virtual path, not a physical path.

This is legal: Server.MapPath("./dbase/dbasefile.mdb")
This is not legal: Server.MapPath("C:\dbase\dbasefile.mdb")

In your case (since the mdb file is in the same directory as the asp file) it is going to be Server.MapPath("./dbase.mdb")

===========================================================
Read this if you want to know how to get a correct reply for your question:
http://www.catb.org/~esr/faqs/smart-questions.html
^^Took that from planoie's profile^^
^^Modified text taken from gbianchi profile^^
===========================================================
Technical Editor for: Professional Search Engine Optimization with ASP.NET
http://www.wiley.com/WileyCDA/WileyTitle/productCd-0470131470.html
Reply By: neil.abachi07 Reply Date: 2/16/2007 11:56:54 AM
thanks for that, it finally appears - awesome!

when it loads, the invalid login message appears straight away and then when i enter the details it says it is incorrect still

neil



Reply By: neil.abachi07 Reply Date: 2/16/2007 12:35:12 PM
This is part of the code that i was given:

'If no match found, EOF is not true.
   if NOT rec.EOF then
      Response.Redirect("somepage.asp") 'Change to page redirect to after login
   else
      blankError="Invalid username." 'EOF is true, no match found.
   end if

twice, on the top and bottom lines it says there is no match but once says EOF is not true and one says EOF is true!

could this be why when i load the page the "Invalid Password" is already on the form and why, regardless of correct details or not, it always comes back Invalid Password?

Thanks

Neil

Reply By: gbianchi Reply Date: 2/16/2007 12:39:13 PM
hi there..

when you said top and bottom lines you refers to the recordset?? cause it's has eof for the last record and bof for the first one (the two of them are null)...

HTH

Gonzalo

===========================================================
Read this if you want to know how to get a correct reply for your question:
http://www.catb.org/~esr/faqs/smart-questions.html
^^Took that from dparsons signature and he Took that from planoie's profile
===========================================================
Reply By: neil.abachi07 Reply Date: 2/16/2007 12:42:32 PM
hi

what i mean is, for that piece of code it says "No match found, EOF is not true" and then "EOF is true, no match found"

How can EOF be true and false when no match is found? Surely that is an error?

neil

Reply By: dparsons Reply Date: 2/16/2007 12:51:43 PM
It can't.  That piece of code is not in a loop so, as such, either the If statement or the else statement will execute.  If the recordset is not EOF then the if portion will be evaluate if the recordset is EOF then the else statement will be evaluated.  Execution inside the if does not fall through to the else statement.

===========================================================
Read this if you want to know how to get a correct reply for your question:
http://www.catb.org/~esr/faqs/smart-questions.html
^^Took that from planoie's profile^^
^^Modified text taken from gbianchi profile^^
===========================================================
Technical Editor for: Professional Search Engine Optimization with ASP.NET
http://www.wiley.com/WileyCDA/WileyTitle/productCd-0470131470.html
Reply By: gbianchi Reply Date: 2/16/2007 12:53:40 PM
somebody makes a mistake there.. eof is true when no match is found...

and if you are getting always invalid password is because you are doing probably the wrong query..

for what i read you are programming in a notepad..

Doug any idea how he can trace the code?? maybe instead of write invalid password show the data you are searching for???

HTH

Gonzalo

===========================================================
Read this if you want to know how to get a correct reply for your question:
http://www.catb.org/~esr/faqs/smart-questions.html
^^Took that from dparsons signature and he Took that from planoie's profile
===========================================================
Reply By: neil.abachi07 Reply Date: 2/16/2007 3:18:58 PM
Hi,

The code used is on the first page - all i did to tweak it was change the table name and the mdb file path. otherwise, the code is as it is on page 1. even if a write or response was used, why is it that there is an invalid password response every time? i have looked at the code and im definate that it references the right tables and cells within.

Neil

Reply By: dparsons Reply Date: 2/16/2007 3:24:53 PM
Oh god, how I wish tracing was available in Classic ><  Sadly, no, no tracing is available to you.  I would suggest doing: Response.Write(sql) does this show the correct SQL Statement? Better yet if you execute it in Access does it return anything?

===========================================================
Read this if you want to know how to get a correct reply for your question:
http://www.catb.org/~esr/faqs/smart-questions.html
^^Took that from planoie's profile^^
^^Modified text taken from gbianchi profile^^
===========================================================
Technical Editor for: Professional Search Engine Optimization with ASP.NET
http://www.wiley.com/WileyCDA/WileyTitle/productCd-0470131470.html
Reply By: neil.abachi07 Reply Date: 2/16/2007 3:39:00 PM
sorry, not sure what you are asking for once i change the statement

neil

Reply By: dparsons Reply Date: 2/16/2007 3:43:35 PM
Replace this line:
set rec=Con.execute(sql)

with
Response.Write(sql)

This will write out the sqlStatement you are passing into Access.  Is it the statement you expect to be sending in?

Also consider changing this:
  Dim Con, sql, rec
   set Con = Server.CreateObject("ADODB.Connection")
  Con.Open "DRIVER={Microsoft Access Driver (*.mdb)}; DBQ=" & Server.MapPath("database.mdb")   
'Select the record matching the username.
   sql = "SELECT * FROM tblusers WHERE UCase(username)=' "& UCase(username) & "' AND UCase(password)=' " & UCase(password) & " ' "
   set rec=Con.execute(sql)
   'If no match found, EOF is not true.
   if NOT rec.EOF then
      Response.Redirect("somepage.asp") 'Change to page redirect to after login
   else
      blankError="Invalid username." 'EOF is true, no match found.
   end if

To this
If username <> "" and password <> "" then
  Dim Con, sql, rec
   set Con = Server.CreateObject("ADODB.Connection")
  Con.Open "DRIVER={Microsoft Access Driver (*.mdb)}; DBQ=" & Server.MapPath("database.mdb")   
'Select the record matching the username.
   sql = "SELECT * FROM tblusers WHERE UCase(username)=' "& UCase(username) & "' AND UCase(password)=' " & UCase(password) & " ' "
   set rec=Con.execute(sql)
   'If no match found, EOF is not true.
   if NOT rec.EOF then
      Response.Redirect("somepage.asp") 'Change to page redirect to after login
   else
      blankError="Invalid username." 'EOF is true, no match found.
   end if
end if

===========================================================
Read this if you want to know how to get a correct reply for your question:
http://www.catb.org/~esr/faqs/smart-questions.html
^^Took that from planoie's profile^^
^^Modified text taken from gbianchi profile^^
===========================================================
Technical Editor for: Professional Search Engine Optimization with ASP.NET
http://www.wiley.com/WileyCDA/WileyTitle/productCd-0470131470.html
Reply By: neil.abachi07 Reply Date: 2/16/2007 3:59:22 PM
Hi,

I will try that now, thanks.

How can i read how the sql statement is accessing the database?

Neil

Reply By: dparsons Reply Date: 2/16/2007 4:08:49 PM
Response.Write(sql)

That will show you your sql statement.

===========================================================
Read this if you want to know how to get a correct reply for your question:
http://www.catb.org/~esr/faqs/smart-questions.html
^^Took that from planoie's profile^^
^^Modified text taken from gbianchi profile^^
===========================================================
Technical Editor for: Professional Search Engine Optimization with ASP.NET
http://www.wiley.com/WileyCDA/WileyTitle/productCd-0470131470.html
Reply By: neil.abachi07 Reply Date: 2/16/2007 4:36:48 PM
cool, when and where will it show up and what sort of thing will i be looking for?

neil

Reply By: dparsons Reply Date: 2/16/2007 4:43:21 PM
...

   sql = "SELECT * FROM tblusers WHERE UCase(username)=' "& UCase(username) & "' AND UCase(password)=' " & UCase(password) & " ' "
response.write(sql)

this will write the value of Sql out to the very top of the screen (will all of the values evaluated) so it might be SELECT * from tblUsers where username = 'Admin' and Password = 'password'

Also you may want to look into this book.
http://www.wrox.com/WileyCDA/WroxTitle/productCd-0764543636.html



===========================================================
Read this if you want to know how to get a correct reply for your question:
http://www.catb.org/~esr/faqs/smart-questions.html
^^Took that from planoie's profile^^
^^Modified text taken from gbianchi profile^^
===========================================================
Technical Editor for: Professional Search Engine Optimization with ASP.NET
http://www.wiley.com/WileyCDA/WileyTitle/productCd-0470131470.html
Reply By: neil.abachi07 Reply Date: 2/16/2007 4:46:23 PM
thanks, i really appreciate all of this.

i will do it asap and tell you the output - my home pc hasnt got IIS installed so i am looking for my XP disk.

Neil

Reply By: neil.abachi07 Reply Date: 2/19/2007 4:18:55 AM
good morning all.....

i tested the website 5 mins ago with no changes after it loaded last friday and today it just shows the code on the page - could this be because i rolled back from IE 7 to IE 6?

Neil

Reply By: dparsons Reply Date: 2/19/2007 10:35:23 AM
Your browser has nothing to do with it.  If you are seeing your code in the browser window, IIS is not setup properly.  (The directory the file is being served from is probably not set up as an application would be my guess.)

===========================================================
Read this if you want to know how to get a correct reply for your question:
http://www.catb.org/~esr/faqs/smart-questions.html
^^Took that from planoie's profile^^
^^Modified text taken from gbianchi profile^^
===========================================================
Technical Editor for: Professional Search Engine Optimization with ASP.NET
http://www.wiley.com/WileyCDA/WileyTitle/productCd-0470131470.html

Discussion:
http://p2p.wrox.com/topic.asp?TOPIC_ID=56429
Reply By: neil.abachi07 Reply Date: 2/19/2007 10:45:26 AM
hi,

how would i change that then?

my main issue is it worked fine last friday, i shut the pc down, booted it up today and it now comes up with code!

Neil

Reply By: dparsons Reply Date: 2/19/2007 10:50:52 AM
Are you navigating to the url e.g. http://localhost or are you going directly to the file in your address bar e.g. file://C:\inetpub\wwwroot\login.asp

If you are doing the latter of the 2, that is why it would only display text, because you aren't executing the code at that point, just opening the file.  

To make sure a directory is running as an application, open the IIS MMC expand the computer node, then expand the website node, you will see a directory listing, right click on the folder you are serving your asp page from and select properties.  A window will open and on that intial screen you will see application settings towards the bottom, if the button labeled "Create" is enabled, click it, hit apply, ok and try browsing to the page again.

===========================================================
Read this if you want to know how to get a correct reply for your question:
http://www.catb.org/~esr/faqs/smart-questions.html
^^Took that from planoie's profile^^
^^Modified text taken from gbianchi profile^^
===========================================================
Technical Editor for: Professional Search Engine Optimization with ASP.NET
http://www.wiley.com/WileyCDA/WileyTitle/productCd-0470131470.html

Discussion:
http://p2p.wrox.com/topic.asp?TOPIC_ID=56429
Reply By: neil.abachi07 Reply Date: 2/19/2007 12:34:28 PM
Hi dparsons,

thanks again, it works now, will put the updated coding in when i get home and then i will tell you if it lets me login or not.

Neil

Reply By: neil.abachi07 Reply Date: 2/19/2007 4:45:46 PM
hey

i changed the response.write and it errored on me with an http 500.100 message
i changed the code below the response.write and i dont get an invalid password message until i try to login and then the same issues - invalid regardless of a corect entry or not.

any ideas?

neil

Reply By: dparsons Reply Date: 2/19/2007 4:52:57 PM
Copy and paste this code, change the string to the database, it should work without error.

<%
dim username, password
username=TRIM(Request("username"))
password=TRIM(Request("password"))

If username <> "" AND password <> "" then
   Dim Con, sql, rec
   set Con = Server.CreateObject("ADODB.Connection")
  Con.Open "DRIVER={Microsoft Access Driver (*.mdb)}; DBQ=" & Server.MapPath("database.mdb")   
'Select the record matching the username.
   sql = "SELECT * FROM tblusers WHERE username='"& UCase(username) & "' AND password='" & UCase(password) & "'"
   set rec=Con.execute(sql)
   'If no match found, EOF is not true.
   if NOT rec.EOF then
      Response.Redirect("somepage.asp") 'Change to page redirect to after login
   else
      blankError="Invalid username." 'EOF is true, no match found.
   end if
else
%>

<html>
    <head>
        <title>Login</title>
    </head>
    <body>
        <form name="productForm" method="post" ID="Form1">
            <center>
                <table border="1" ID="Table1">
                    <tr>
                        <td colspan="2">
                            <%

if blankError<>"" then
Response.Write("<center><font color='red' size='3'>"&blankError&"</font></center>")
end if
%>
                        </td>
                    </tr>
                    <tr>
                        <td><Strong><font face="courier new" size="3">Username:</font></Strong></td>
                        <td><input type="text" name="username" size="35" ID="Text1"></td>
                    </tr>
                    <tr>
                        <td><Strong><font face="courier new" size="3">Password</font></Strong></td>
                        <td><input type="password" name="password" size="35" ID="Password1"></td>
                    </tr>
                    <tr>
                        <td colspan="2" align="center"><input type="submit" name="loginButton" value="Login" ID="Submit1">
                            <input type="reset" name="reset" value="Clear" ID="Reset1"></td>
                    </tr>
                </table>
            </center>
        </form>
    </body>
</html>
<%end if%>

===========================================================
Read this if you want to know how to get a correct reply for your question:
http://www.catb.org/~esr/faqs/smart-questions.html
^^Took that from planoie's profile^^
^^Modified text taken from gbianchi profile^^
===========================================================
Technical Editor for: Professional Search Engine Optimization with ASP.NET
http://www.wiley.com/WileyCDA/WileyTitle/productCd-0470131470.html

Discussion:
http://p2p.wrox.com/topic.asp?TOPIC_ID=56429
Reply By: neil.abachi07 Reply Date: 2/19/2007 4:55:54 PM
thanks for the code,

this is what i get -

Error Type:
Microsoft VBScript compilation (0x800A03F6)
Expected 'End'
/abachi/login.asp, line 36

Reply By: dparsons Reply Date: 2/19/2007 6:03:05 PM
Ummm?  I just executed this code on my webserver and it worked fine.  Are you using the code that is pasted above or the code that came to you in your email?

I edited the post due to a typo and that may be the problem your having.

===========================================================
Read this if you want to know how to get a correct reply for your question:
http://www.catb.org/~esr/faqs/smart-questions.html
^^Took that from planoie's profile^^
^^Modified text taken from gbianchi profile^^
===========================================================
Technical Editor for: Professional Search Engine Optimization with ASP.NET
http://www.wiley.com/WileyCDA/WileyTitle/productCd-0470131470.html

Discussion:
http://p2p.wrox.com/topic.asp?TOPIC_ID=56429
Reply By: neil.abachi07 Reply Date: 2/19/2007 6:17:51 PM
ok................

IT WORKS!!!!!

i cannot thank you enough for all your help and support. is it relatively easy to setup a dynamic redirect? i have specified a series of webpages in my table (different one for each login) and i would like to redirect to there.

Neil

:D :D :D :D

Reply By: dparsons Reply Date: 2/19/2007 6:27:16 PM
It depends you could use this statement
"SELECT * FROM tblusers WHERE username='"& UCase(username) & "' AND password='" & UCase(password) & "'"

as long as the the page you are redirecting to belongs to that table you could do something like:

Response.Redirect(rs("redirectPage"))

Else you will have to open another query like

SELECT link From <table> where Username ='" & username &"'"

I would highly suggest picking up a book and reading up on ASP as its nearly impossible to get this kind of response to threads all the time, reading will save you alot of headaches for sure.

Glad you got it working and good luck.

===========================================================
Read this if you want to know how to get a correct reply for your question:
http://www.catb.org/~esr/faqs/smart-questions.html
^^Took that from planoie's profile^^
^^Modified text taken from gbianchi profile^^
===========================================================
Technical Editor for: Professional Search Engine Optimization with ASP.NET
http://www.wiley.com/WileyCDA/WileyTitle/productCd-0470131470.html

Discussion:
http://p2p.wrox.com/topic.asp?TOPIC_ID=56429
Reply By: neil.abachi07 Reply Date: 2/19/2007 6:29:37 PM
hi,

my dad is looking into an asp bible in the morning!

i have been scouring the code as if i enter incorrect details then the page just goes blank. is this something to do with the else blankerror statement?

Neil

Reply By: dparsons Reply Date: 2/19/2007 6:37:22 PM
No, it has to do with my containing IF ELSE block.  This is not the way you should implement this by any means, however, to get this working for you that is how i wrote it.

By design, if you enter a username and password the code enters the If protion of the statement so, even if the credentials are incorrect, the ELSE statement (the part that displays the form) will NEVER execute.  

Alternatively you could adjust this so that the user sees the form again or that they get redirected to a page telling them they have supplied invalid credentials.  That, however, I will leave up to you to tinker with ;]

===========================================================
Read this if you want to know how to get a correct reply for your question:
http://www.catb.org/~esr/faqs/smart-questions.html
^^Took that from planoie's profile^^
^^Modified text taken from gbianchi profile^^
===========================================================
Technical Editor for: Professional Search Engine Optimization with ASP.NET
http://www.wiley.com/WileyCDA/WileyTitle/productCd-0470131470.html

Discussion:
http://p2p.wrox.com/topic.asp?TOPIC_ID=56429
Reply By: neil.abachi07 Reply Date: 2/19/2007 6:40:11 PM
i appreciate that, i'm gonna take a stab at using some of the code that is used for the correct login and redirect to the login page again and use a popup window using VB.

thank you once more for all your help, none of this would have been possible without your valuable knowledge and input.

Kind regards

neil

Reply By: neil.abachi07 Reply Date: 2/20/2007 12:22:39 PM
Hi, all good so far,

I created in my database a field with a link to another page on the website where (depending on the user logging in), it will be dynamic depending on the username and password.

using the code published on page 3, im guessing i need to add the following:

1. at the top in dim, add the field name (redirect)

2. underneath, write redirect=TRIM(Request("redirect"))

3. sql = "SELECT * FROM users WHERE username='"& UCase(username) & "' AND password='" & UCase(password) & "' AND redirect='" & UCase(redirect) & "'" ( i added selecting the redirect field into the sql)

4. this is where i get stuck - i have the Response.Redirect() and i am tempted to add the selected field into the brackets but i am not sure that this would work, i had a stab at it and inserted the code listed above into the rest of the ASP page and it still loaded and allowed the login but the redirect failed.

Any ideas?

Thanks

Neil

Reply By: neil.abachi07 Reply Date: 2/20/2007 12:23:44 PM
quote:
Originally posted by neil.abachi07

Hi, all good so far,

I created in my database a field with a link to another page on the website where (depending on the user logging in), it will be dynamic and redirect to the correct page

using the code published on page 3, im guessing i needed to add the following:

1. at the top in dim, add the field name (redirect)

2. underneath, write redirect=TRIM(Request("redirect"))

3. sql = "SELECT * FROM users WHERE username='"& UCase(username) & "' AND password='" & UCase(password) & "' AND redirect='" & UCase(redirect) & "'" ( i added selecting the redirect field into the sql)

4. this is where i get stuck - i have the Response.Redirect() and i am tempted to add the selected field into the brackets but i am not sure that this would work, i had a stab at it and inserted the code listed above into the rest of the ASP page and it still loaded and allowed the login but the redirect failed.

Any ideas?

Thanks

Neil





Reply By: dparsons Reply Date: 2/20/2007 1:38:23 PM
Is the path of the page you are redirecting to coming through a query string value or is it on the form somewhere?  If it isnt, Request("redirect") does you no good.

Request is used to get values out of a query string or from fields on a form (Request.QueryString and Request.Form respsectively)

Since you said that the login determines the redirect
redirect='" & UCase(redirect) & "'"

Does you no good either as you are telling the SQL Statement: "Return me all rows where the username equals this, password equals this, and redirect equals this"

In theory, if you have a column in your Users table that tells you where the user needs to go (lets call it redirect) your select statement will return a row that containst that column based on this sql statement:

"SELECT * FROM users WHERE username='"& UCase(username) & "' AND password='" & UCase(password) & "'"

So you should be able to do this:

Response.redirect(rec("redirect"))

===========================================================
Read this if you want to know how to get a correct reply for your question:
http://www.catb.org/~esr/faqs/smart-questions.html
^^Took that from planoie's profile^^
^^Modified text taken from gbianchi profile^^
===========================================================
Technical Editor for: Professional Search Engine Optimization with ASP.NET
http://www.wiley.com/WileyCDA/WileyTitle/productCd-0470131470.html

Discussion:
http://p2p.wrox.com/topic.asp?TOPIC_ID=56429
Reply By: neil.abachi07 Reply Date: 2/20/2007 3:11:48 PM
i see

i have a column in my table called redirect, the pages listed are in the same folder as the asp page but i guess thats not the issue?

all i have to do then is add the "rec" before the column name in the redirect?
do i have to declare redirect anywhere or as its in the db called earlier that will do?

thanks

Reply By: dparsons Reply Date: 2/20/2007 3:21:06 PM
No.  In this case rec is a recordset, think of a recordset like an array.  What rec("redirect") says is retrieve me the value that exists at the "redirect" position.  

In this case you dont have to worry about multiple rows because this query should only return 1 row.

===========================================================
Read this if you want to know how to get a correct reply for your question:
http://www.catb.org/~esr/faqs/smart-questions.html
^^Took that from planoie's profile^^
^^Modified text taken from gbianchi profile^^
===========================================================
Technical Editor for: Professional Search Engine Optimization with ASP.NET
http://www.wiley.com/WileyCDA/WileyTitle/productCd-0470131470.html

Discussion:
http://p2p.wrox.com/topic.asp?TOPIC_ID=56429
Reply By: neil.abachi07 Reply Date: 2/20/2007 3:26:18 PM
just so you know - the rec(redirect) worked so thanks very much for that, wasnt sure about variables etc so cheers for clearing that up

neil

Reply By: neil.abachi07 Reply Date: 2/21/2007 5:18:55 AM
Hi,

do you know of a resource or where i can go to read up on protecting certain pages so that the user has to be logged in to view?

Thanks

Reply By: dparsons Reply Date: 2/21/2007 7:56:48 AM
Setup some sort of Authentication
http://www.4guysfromrolla.com/webtech/050499-1.shtml
http://www.15seconds.com/issue/981104.htm
http://www.asp101.com/articles/valko/authentication/default.asp
http://www.tutorialized.com/tutorials/ASP/User-Authentication/1
http://www.kamath.com/tutorials/tut003_auth.asp

===========================================================
Read this if you want to know how to get a correct reply for your question:
http://www.catb.org/~esr/faqs/smart-questions.html
^^Took that from planoie's profile^^
^^Modified text taken from gbianchi profile^^
===========================================================
Technical Editor for: Professional Search Engine Optimization with ASP.NET
http://www.wiley.com/WileyCDA/WileyTitle/productCd-0470131470.html

Discussion:
http://p2p.wrox.com/topic.asp?TOPIC_ID=56429
Reply By: invisible bunny king Reply Date: 2/23/2007 2:24:01 PM
Hi.
I have been having the same problem.
Thanks for all the advice. It has gotte me much closer to getting it to work. My login screen will finally show up!
However, when I submit the info I get an error saying:
Microsoft JET Database Engine error '80040e10'

No value given for one or more required parameters.

/logincode3.asp, line 15

I don't know what is missing! Here is my code (though it will look familiar to what you have posted). It claims the error on the .execute line:

<%
dim username, password
username=TRIM(Request.Form("Uname"))
password=TRIM(Request.Form("Pass"))

If username <> "" AND password <> "" then
   Dim objConn, sql, rec, dbPath
   dbPath="/db/HockeyCards.mdb"
   set objConn = Server.CreateObject("ADODB.Connection")
  objConn.Open "Provider=Microsoft.Jet.OLEDB.4.0; Data Source=" & Server.MapPath(dbPath) & ";"   
'Select the record matching the username.
   sql = "SELECT * FROM Customerlist WHERE Uname='"& username & "' AND Pass='" & password & "'"
   Set rec= objConn.execute(sql)
   'If no match found, EOF is not true.
   if NOT rec.EOF then
      Response.Redirect("welcome.asp") 'Change to page redirect to after login
   else
      blankError="Invalid username." 'EOF is true, no match found.
   end if
else
%>

Any thoughts? The taste of victory seems so close now....

Now is the only thing that's real.
Reply By: gbianchi Reply Date: 2/23/2007 2:26:14 PM
probably a mistype...

sql = "SELECT * FROM Customerlist WHERE Uname='"& username & "' AND Pass='" & password & "'"

should probably be:

sql = "SELECT * FROM Customerlist WHERE Username='"& username & "' AND Pass='" & password & "'"

HTH

Gonzalo

===========================================================
Read this if you want to know how to get a correct reply for your question:
http://www.catb.org/~esr/faqs/smart-questions.html
^^Took that from dparsons signature and he Took that from planoie's profile
===========================================================
Reply By: invisible bunny king Reply Date: 2/23/2007 2:33:02 PM
Hi.
I'm not sure if that is it. You see, in my form, the fields are named Uname and Pass. Therefore, they need to be named that in the sql statement, right? Also, this is how they are named in the Access table being searched.

Now is the only thing that's real.
Reply By: dparsons Reply Date: 2/23/2007 2:33:54 PM
check this out
http://www.adopenstatic.com/faq/80040e10.asp

===========================================================
Read this if you want to know how to get a correct reply for your question:
http://www.catb.org/~esr/faqs/smart-questions.html
^^Took that from planoie's profile^^
^^Modified text taken from gbianchi profile^^
===========================================================
Technical Editor for: Professional Search Engine Optimization with ASP.NET
http://www.wiley.com/WileyCDA/WileyTitle/productCd-0470131470.html

Discussion:
http://p2p.wrox.com/topic.asp?TOPIC_ID=56429
Reply By: dparsons Reply Date: 2/23/2007 2:36:31 PM
Also, try this:

do response.write(sql) does it equate to a SQL statement you can execute inside of access?

===========================================================
Read this if you want to know how to get a correct reply for your question:
http://www.catb.org/~esr/faqs/smart-questions.html
^^Took that from planoie's profile^^
^^Modified text taken from gbianchi profile^^
===========================================================
Technical Editor for: Professional Search Engine Optimization with ASP.NET
http://www.wiley.com/WileyCDA/WileyTitle/productCd-0470131470.html

Discussion:
http://p2p.wrox.com/topic.asp?TOPIC_ID=56429
Reply By: neil.abachi07 Reply Date: 2/26/2007 11:55:00 AM
hey, you could rename your fields in your table to username and password to avoid confusion as to how it goes in the sql statement???

Reply By: neil.abachi07 Reply Date: 2/26/2007 7:24:17 PM
hey, how can i response.redirect to a parent frame?

thanks

Reply By: dparsons Reply Date: 2/26/2007 7:32:09 PM
This is the thread that won't die =P  Anyway you can't use response.redirect to do this, you have to use some Javascript trickery and a Response.Write():

Dim sJavaScript
sJavaScript = "<script language=javascript>"
sJavaScript = sJavaScript & "parent.frames[n].location.href='page.asp';"
sJavaScript = sJavaScript & "</scr" & "ipt>"

response.write(sJavaScript)

In the line: parent.frames[n].location.href='page.asp'; n is equal to an integer value OR the name of the frame.  If using the frame name, surround it in ' '

Also, please post all further questions in the Classic ASP Beginners forum, I wrote this entire reply in .NET and totally forgot we were discussing classic ;]

hth



===========================================================
Read this if you want to know how to get a correct reply for your question:
http://www.catb.org/~esr/faqs/smart-questions.html
^^Took that from planoie's profile^^
^^Modified text taken from gbianchi profile^^
===========================================================
Technical Editor for: Professional Search Engine Optimization with ASP.NET
http://www.wiley.com/WileyCDA/WileyTitle/productCd-0470131470.html

Discussion:
http://p2p.wrox.com/topic.asp?TOPIC_ID=56429
Reply By: invisible bunny king Reply Date: 2/27/2007 1:16:36 PM
Hi again.

Well, I took a few days off to try and get my login page working. I found some great articles on the topic, and tried out different approaches to fixing my problem. However, I truly am stumped at this part. I receive an error message that is as follows:

Microsoft VBScript runtime  error '800a01b6'
Object doesn't support this property or method: 'EOF'
/logincode3.asp, line 17

I understand that the EOF has to do with the login info (i think), but I do not understand why it isn't supported.
Below is my code again. I have tried variations of what is there, but none of them work.
Any thoughts?
<%
dim username, password
username=TRIM(Request.Form("Uname"))
password=TRIM(Request.Form("Pass"))

If username <> "" AND password <> "" then
   Dim objConn, sql, rec, dbPath
   dbPath="/db/HockeyCards.mdb"
   set objConn = Server.CreateObject("ADODB.Connection")
  objConn.Open "Provider=Microsoft.Jet.OLEDB.4.0; Data Source=" & Server.MapPath(dbPath) & ";"   
'Select the record matching the username.
   sql = "SELECT * FROM CustomerList WHERE Uname='"& username & "' AND Pass='" & password & "'"
   response.write(sql)
   'If no match found, EOF is not true.
   if NOT response.EOF then
      Response.Redirect("sorry.asp") 'Change to page redirect to after login
   else
      blankError="Invalid username." 'EOF is true, no match found.
   end if
else
%>
Note: I have tried to "highlight" the line in question.

Now is the only thing that's real.
Reply By: dparsons Reply Date: 2/27/2007 1:29:16 PM
....You don't have a recordset object open.  .EOF stands for End Of File and it is how you determine if a Recordset (or datastream) has read to the end of file.  The response object does not, in fact, support EOF nor will it contain the data you are looking for in your if statement.  The response object has to do with sending data to the browser.

you need to do this:

set rec=Con.execute(sql)
   'If no match found, EOF is not true.
   if NOT rec.EOF then
      Response.Redirect("somepage.asp") 'Change to page redirect to after login
   else
      blankError="Invalid username." 'EOF is true, no match found.
   end if

In this instance you implicity convert the variable rec to a recordset.  

I think you will find that that will work for you.

Lastly, as I said to neil please post all further questions in the Classic ASP Beginners forum since this forum is for .NET 1.1.

Thanks.

===========================================================
Read this if you want to know how to get a correct reply for your question:
http://www.catb.org/~esr/faqs/smart-questions.html
^^Took that from planoie's profile^^
^^Modified text taken from gbianchi profile^^
===========================================================
Technical Editor for: Professional Search Engine Optimization with ASP.NET
http://www.wiley.com/WileyCDA/WileyTitle/productCd-0470131470.html

Discussion:
http://p2p.wrox.com/topic.asp?TOPIC_ID=56429
Reply By: sahanar Reply Date: 4/16/2008 11:47:23 PM
hi,

i am new to asp. problem is i am  not able to execute my asp files. i have iis in my system. but inside iis->web sites->empty
i should find default web site inside web sites folder. but that folder is empty.and even ftp sites folder also empty. i do not admin rights. so what i can do to execute my asp files.

Thanks






Go to topic 70625

Return to index page 1