Web Wiz - Green Windows Web Hosting

  New Posts New Posts RSS Feed - what’s wrong with this code..?
  FAQ FAQ  Forum Search   Events   Register Register  Login Login

what’s wrong with this code..?

 Post Reply Post Reply Page  12>
Author
fernan82 View Drop Down
Mod Builder Group
Mod Builder Group
Avatar

Joined: 17 November 2002
Location: United States
Status: Offline
Points: 362
Post Options Post Options   Thanks (0) Thanks(0)   Quote fernan82 Quote  Post ReplyReply Direct Link To This Post Topic: what’s wrong with this code..?
    Posted: 15 May 2003 at 2:49pm

I use this code for my site login script (it's basically -borg-'s code slightly modified)......... The problem is that i got a JavaScript pop up at the end of the code (text in red) and all the code is getting executed but those lines so i don't get no pop up when the password is incorrect. Any ideas why this is happening? here's the code:

'If a username has been entered check that the password is correct
If NOT strUsername = "" Then


 'Read the various forums from the database
 'Initalise the strSQL variable with an SQL statement to query the database
 strSQL = "SELECT tblAuthor.Password, tblAuthor.Salt, tblAuthor.Author_ID, tblAuthor.User_code "
 strSQL = strSQL & "FROM tblAuthor "
 strSQL = strSQL & "WHERE tblAuthor.Username = '" & strUsername & "';"

 'Query the database
 rsCommon.Open strSQL, adoCon

 'If the query has returned a value to the recordset then check the password is correct

 If NOT rsCommon.EOF Then


  'Encrypt password so we can check it against the encypted password in the database
  'Read in the salt
  strPassword = strPassword & rsCommon("Salt")

  'Encrypt the entered password
  strPassword = HashEncode(strPassword)


  'Check the encrypted password is correct, if it is get the user ID and set a cookie

  If strPassword = rsCommon("Password") Then


   'Read in the users ID number and whether they want to be automactically logged in when they return to the forum
   lngUserID = CLng(rsCommon("Author_ID"))
   strUserCode = rsCommon("User_code")

   'Write a cookie with the User ID number so the user logged in throughout the forum
   'Write the cookie with the name Forum containing the value UserID number
   Response.Cookies("Forum")("UID") = strUserCode
   If CBool(Request.Form("ActiveUsers")) = False Then
    Response.Cookies("Forum")("Hide") = True
   Else
    Response.Cookies("Forum")("Hide") = False
   End If


   'If the user has selected to be remebered when they next login then set the expiry date for the cookie for 1 year
   If blnAutoLogin = True Then

    'Set the expiry date for 1 year
    'If no expiry date is set the cookie is deleted from the users system 20 minutes after they leave the forum
    Response.Cookies("Forum").Expires = DateAdd("yyyy", 1, Now())
   End If

   'Reset Server Objects
   rsCommon.Close
   Set rsCommon = Nothing
   adoCon.Close
   Set adoCon = Nothing
   Response.Redirect strNewRedir

         End If

 End If

'Popup alert if username or password is invalid
Response.Write("<script  language=""JavaScript"">")
Response.Write("alert('Invalid Username And/Or Password');")
Response.Write("</script>")

End If

FeRnAN
Back to Top
farrukh View Drop Down
Groupie
Groupie
Avatar

Joined: 10 May 2002
Location: Pakistan
Status: Offline
Points: 147
Post Options Post Options   Thanks (0) Thanks(0)   Quote farrukh Quote  Post ReplyReply Direct Link To This Post Posted: 15 May 2003 at 3:14pm
Originally posted by fernan82 fernan82 wrote:

'Popup alert if username or password is invalid
Response.Write("<script  language=""JavaScript"">")
Response.Write("alert('Invalid Username And/Or Password');")
Response.Write("</script>")


make asp tag close
%>

<script  language="JavaScript">
window.alert("Invalid Username And/Or Password")
</script>

<%
      asp code here
%>

check out the view source of the page and see what is actually written in your code. I will clear your more.
i have collected some nice avatars (37) and smileys (227) here you can download
http://www24.brinkster.com/webmastertool/download.html
Back to Top
fernan82 View Drop Down
Mod Builder Group
Mod Builder Group
Avatar

Joined: 17 November 2002
Location: United States
Status: Offline
Points: 362
Post Options Post Options   Thanks (0) Thanks(0)   Quote fernan82 Quote  Post ReplyReply Direct Link To This Post Posted: 15 May 2003 at 4:25pm

I tried that before and it didn't work neither

right after that code i got this code:

'Reset Server Objects
Set rsCommon = Nothing
adoCon.Close
Set adoCon = Nothing

If blnGuest Then

'Redirect to the page where this script was loaded from
If strNewRedir = "" Then strNewRedir = Request.ServerVariables("URL")
If strNewRedir <> Request.ServerVariables("URL") Then Response.Redirect strNewRedir

That way after the login or log off the user is redirected to the same page they were at (i got this script included in all pages on my site)...so i can't really look at the source cuz i get redirected right away...

If i comment out the later code it will display the javascript pop up but then the script wouldn't work correctly, so the actual problem i guess is that the redirect is being executed before the javascript.........how can that happen if the javascript is first..???



Edited by fernan82
FeRnAN
Back to Top
fernan82 View Drop Down
Mod Builder Group
Mod Builder Group
Avatar

Joined: 17 November 2002
Location: United States
Status: Offline
Points: 362
Post Options Post Options   Thanks (0) Thanks(0)   Quote fernan82 Quote  Post ReplyReply Direct Link To This Post Posted: 15 May 2003 at 4:52pm
I figure the server doesn't start spitting out the html and javascript until it has procesed all the ASP code, so it executes the Response.Redirect command before it even spits any html or javascript out........ what can i do about it?
FeRnAN
Back to Top
fernan82 View Drop Down
Mod Builder Group
Mod Builder Group
Avatar

Joined: 17 November 2002
Location: United States
Status: Offline
Points: 362
Post Options Post Options   Thanks (0) Thanks(0)   Quote fernan82 Quote  Post ReplyReply Direct Link To This Post Posted: 15 May 2003 at 5:40pm

I've tried everything,

i made a new file with just the javascript pop up and a <% Response.Redirect %> line and change my login script to redirect to that page but it'll also execute the asp line and not the javascript, i tried making an .htm file with just the javascript and include it using include file and it didn't work neither, it executes the Response.Redirect commands but it doesn't spit out any javascript or html to the browser...

FeRnAN
Back to Top
Gullanian View Drop Down
Senior Member
Senior Member
Avatar

Joined: 04 January 2002
Location: England
Status: Offline
Points: 4373
Post Options Post Options   Thanks (0) Thanks(0)   Quote Gullanian Quote  Post ReplyReply Direct Link To This Post Posted: 16 May 2003 at 5:05am

Can you copy and paste the error?

Have you got any HTML before that code?  Even an <HTML> tag?

Back to Top
Mart View Drop Down
Senior Member
Senior Member
Avatar

Joined: 30 November 2002
Status: Offline
Points: 2304
Post Options Post Options   Thanks (0) Thanks(0)   Quote Mart Quote  Post ReplyReply Direct Link To This Post Posted: 16 May 2003 at 9:17am

'Popup alert if username or password is invalid
Response.Write("<script  language=""JavaScript"">")
Response.Write("alert('Invalid Username And/Or Password');")

Response.Write("window.location=""page.asp"";")
Response.Write("</script>")

Uses javascript to redirect the user...

Back to Top
fernan82 View Drop Down
Mod Builder Group
Mod Builder Group
Avatar

Joined: 17 November 2002
Location: United States
Status: Offline
Points: 362
Post Options Post Options   Thanks (0) Thanks(0)   Quote fernan82 Quote  Post ReplyReply Direct Link To This Post Posted: 16 May 2003 at 2:44pm
Originally posted by Gullanian Gullanian wrote:

Can you copy and paste the error?

Have you got any HTML before that code?  Even an <HTML> tag?

I can't cuz there's no error, basicly the ASP script is running on the background and is not spitting out any HTML or JavaScript at all, and yes i do have an <html> tag on the page and also i got quite a bit of JavaScript on the page even before any ASP code but it's not being sent to the browser, it executes the ASP before it starts spitting out HTML, so since i got a Response.Redirect on the code it just redirects me to the next page without even spitting any html out....

Originally posted by Mart Mart wrote:

'Popup alert if username or password is invalid
Response.Write("<script  language=""JavaScript"">")
Response.Write("alert('Invalid Username And/Or Password');")

Response.Write("window.location=""page.asp"";")
Response.Write("</script>")

Uses javascript to redirect the user...

Thanks, that does works, the reason i didn't wanted to do it that way is because if the user's browser doesn't support Java or is not enabled then it'll stay on the empty page, i guess i'm gonna have to use one of those "Click here if you're not redirected" link but that wouldn't look too good (at least i don't like it like that) but i guess i'm gonna have to settle with that for now........

Anyone knows if that's a limitation on ASP or if there's something that can be done about it??

Thanks.

FeRnAN
Back to Top
 Post Reply Post Reply Page  12>

Forum Jump Forum Permissions View Drop Down

Forum Software by Web Wiz Forums® version 12.08
Copyright ©2001-2026 Web Wiz Ltd.


Become a Fan on Facebook Follow us on X Connect with us on LinkedIn Web Wiz Blogs
About Web Wiz | Contact Web Wiz | Terms & Conditions | Cookies | Privacy Notice

Web Wiz is the trading name of Web Wiz Ltd. Company registration No. 05977755. Registered in England and Wales.
Registered office: Web Wiz Ltd, Unit 18, The Glenmore Centre, Fancy Road, Poole, Dorset, BH12 4FB, UK.

Prices exclude VAT at 20% unless otherwise stated. VAT No. GB988999105 - $, € prices shown as a guideline only.

Copyright ©2001-2026 Web Wiz Ltd. All rights reserved.