Can't find bug

This is a discussion on "Can't find bug" within the Classic ASP section. This forum, and the thread "Can't find bug are both part of the Program Your Website category.



Go Back   Webforumz.com > Main Forums > Program Your Website > Classic ASP

Notices


Closed Thread
 
LinkBack Thread Tools
  #1 (permalink)  
Old Sep 5th, 2003, 19:34
Reputable Member
Join Date: Sep 2003
Location: USA
Posts: 112
Thanks: 0
Thanked 0 Times in 0 Posts
Can't find bug

I have this script
Code: Select all
vSQL= join(array("SELECT", selectItem, _
							"FROM", tableName, _
							"WHERE", criteriaName, "=", ID), " ")
response.write "

" & vSQL

	set valueClient = Server.CreateObject("ADODB.Recordset")
	valueClient.open vSQL, conn,3,3
	
response.write ":" & valueClient.recordcount
if not valueClient.EOF then 
	response.write "fish"
	GetValue=valueClient(0)
else
	response.write "cow"
	GetValue = ""
end if
response.write ":" & GetValue
valueClient.close
and it was working fine
the SQL printed out is right
put it doesn't print out the recordcount or anything after that.

I'm completely baffelled.

I'm sure when the answer comes it will be some stupid answer and I would appreciate any help.

jakyra

  #2 (permalink)  
Old Sep 5th, 2003, 19:58
Rob's Avatar
Rob Rob is offline
Head Admin & CEO

SuperMember
Join Date: Jul 2003
Location: at my desk
Age: 34
Posts: 2,952
Blog Entries: 7
Thanks: 7
Thanked 4 Times in 4 Posts
Send a message via MSN to Rob Send a message via Skype™ to Rob
Can you post the entire page?...
and also the generated sql statement?

Cheers,
__________________
Rob - SEO Specialist
Owner & Founder of Webforumz.com

I am currently unavailable for private work
  #3 (permalink)  
Old Sep 5th, 2003, 20:43
Reputable Member
Join Date: Sep 2003
Location: USA
Posts: 112
Thanks: 0
Thanked 0 Times in 0 Posts
The I have two SQL statements in the page I'm trying to load.
SELECT PermissionText FROM TblPermissions WHERE PermissionLevel = 4

SELECT NameFirst FROM TblIndividuals WHERE ID = 1850

both test out fine on the local copy of the database (which is synched with the online one.)

the lines immediately proceeding and the calling lines are (respectively):

Session("user") = ID
Session("ForceChange") = ForceChange
Session("myState") = Permissions
Session("myTeacherID") = TeacherID
Session("mySchoolCode") = SchoolCode
myStatus = GetValue(Permissions, "permissions")
myName = GetValue( ID, "reviewer")
Session("myStatus") = myStatus
Session("myName") =myName

which returns the following if printed out
user: 1850
ForceChange: False
myState: 4
myTeacherID:
mySchoolCode:
myStatus:
myName:



The entire function is :
Code: Select all
<% 
	function GetValue(ID, itemType)
		'The ID is the ID number of the item.
		' itemType controls what lookup you use. i.e. culture, level, reviewer
		
		dim  selectItem
		dim tableName
		dim criteriaName

		if ID = ""  or itemType = "" then exit function
		if not isNumeric(ID) then exit function
	
		itemType = LCase(itemType)
			
		SELECT Case itemType
		case "culture"
			selectItem="Culture"
			tableName="TblCultures"
			criteriaName="ID"
		case "level"
			selectItem= "MyLevel"
			tableName="TblLevels"
			criteriaName="LevelID"
		case "reviewer"
			selectItem="NameFirst"
			tableName="TblIndividuals"
			criteriaName="ID"
		case "email"
			selectItem="Email"
			tableName="TblIndividuals"
			criteriaName="ID"
		case "reviewerlocation"
			selectItem = "NameFirst & ' ' & NameLast & iif(Location>'', ', ' & Location, '') as reviewer"
			tableName="TblIndividuals"
			criteriaName="ID"
		case "permissions"
			selectItem="PermissionText"
			tableName="TblPermissions"
			criteriaName="PermissionLevel"
		case else
			exit function
		end Select
		
			vSQL= join(array("SELECT", selectItem, _
										"FROM", tableName, _
										"WHERE", criteriaName, "=", ID), " ")
			response.write "

" & vSQL
			
				set valueClient = Server.CreateObject("ADODB.Recordset")
				valueClient.open vSQL, conn,3,3
				
			response.write ":" & valueClient.recordcount
			if not valueClient.EOF then 
				GetValue=valueClient(0)
			else
				GetValue = ""
			end if
			response.write ":" & GetValue
			valueClient.close
	end function
%>
Is that enough? I'll put the calling page and the relevant function calls in another post so it's easier to read (or ignore)

thanks!
jakyra
  #4 (permalink)  
Old Sep 5th, 2003, 20:44
Reputable Member
Join Date: Sep 2003
Location: USA
Posts: 112
Thanks: 0
Thanked 0 Times in 0 Posts
Page of originating code

Code: Select all
<%@LANGUAGE="VBSCRIPT"%>
   
	
	

<% 
	Username=Request.Form("UserName")
	Password=Cryptor.Crypt (strSalt, Request.Form("Password"))
%>
<%

	'check to see if the username and password combo are in the table
	SQL="SELECT * FROM Table1 WHERE Username='" & Username & "' AND Password='" & password & "'"
'	response.write "

" &  SQL
	set myclient = Server.CreateObject("ADODB.Recordset")
	myclient.open SQL, Sconn, 3, 3
	 
	if  myclient.EOF then 'username and password do not match
			myclient.close
			
			'see if this user has tried to login and failed before
			SQL = "SELECT Username, attempts, lockout FROM TblAttempts WHERE Username ='" & Username & "'"
			myclient.open SQL, Sconn, 3, 3
			
		 if myclient.EOF then  'if not, then add them to the table and set the number of tries equal to 1
	'		myclient.close
			Sconn.execute "INSERT INTO TblAttempts (Username, attempts) VALUES ('" & Username & "', 1)"
				response.cookies("ChildLit")("message")  = "Login failed. User names and passwords are case sensitive and cannot contain spaces. Please check your user name and password and try again."
		 else 'if so (user hasn't tried before)
		 	attempts = myclient("attempts")
			if attempts = 2 then  'if this is the third failed login, then lock them out
				myclient.close
				Sconn.execute "UPDATE TblAttempts SET lockout = True WHERE Username='" & Username & "'"
%>
				
<%
				session.abandon
				response.redirect "Lockout.html"
			else 'if not, give them another try
				attempts = attempts+1 
				response.cookies("ChildLit")("message")  = "Login failed. User names and passwords are case sensitive and cannot contain spaces. Please check your user name and password and try again."
				Sconn.execute "UPDATE TblAttempts SET attempts = " & attempts & "  WHERE Username='" & Username & "'"
				
				'record the number of tries in a cookie for the index page
				end if 'if myclient("attempts") = 2 then
		end if 'if myclient.EOF then  'user hasn't tried before

		myclient.close
%>
		
<%
		response.redirect "index.asp"

	else 'Username and password match
		ID = myclient("ID")
		ForceChange = myclient("ForceChange")
		myclient.close
		
		SQL = "INSERT INTO TblSession (UserID, Event) VALUES(" & ID & ", 'Login')"
'		response.write SQL
		Sconn.execute SQL
		
		SQL = "UPDATE TblAttempts SET attempts = 0 WHERE Username='" & Username & "'"
		Sconn.execute  SQL
%>


<%
		SQL = "SELECT Permissions, TeacherID, SchoolCode FROM TblIndividuals WHERE ID = " & ID
		set myclient = Server.CreateObject("ADODB.Recordset")
		myclient.open SQL, conn, 3, 3
		GetFields(myclient)  <----- this is a function that loads a recordset into variables of the same name.
		myclient.close

%>

<%

		Session("user") = ID
		Session("ForceChange") = ForceChange
		Session("myState") = Permissions
		Session("myTeacherID") = TeacherID
		Session("mySchoolCode") = SchoolCode
		myStatus =  GetValue(Permissions, "permissions")
		myName =  GetValue( ID, "reviewer")
'		response.write myStatus & "
" & myName
		Session("myStatus") = myStatus
		Session("myName") =myName
		response.cookies("ChildLit")("message")  = ""
	dim i
	For Each i in Session.Contents
	  Response.Write(i & ": " & Session.Contents(i) & "
" )
	Next
				
		if ForceChange then 
			response.cookies("ChildLit")("FirstLogin") = True
			if SchoolCode =  "StKate" then 
				response.redirect "StKateQuestions.asp"
			else
				response.redirect "PasswordChange.asp"
			end if
		else
			response.cookies("ChildLit")("FirstLogin") = False
			if myStatus= "Staff" then 
	'			response.redirect "StaffMailingListMgt.asp"
			else
	'			response.redirect "ReviewEntry.asp"
			end if
		end if
	end if
	
%>
  #5 (permalink)  
Old Sep 8th, 2003, 08:32
Highly Reputable Member
Join Date: Jul 2003
Location: Ipswich, UK
Posts: 690
Thanks: 0
Thanked 0 Times in 0 Posts
im abit concerned about all the times you have included the same file - #include file="Code/SecurityClose.asp"

Are you aware that includes are processed before the asp code?
  #6 (permalink)  
Old Sep 8th, 2003, 15:24
Reputable Member
Join Date: Sep 2003
Location: USA
Posts: 112
Thanks: 0
Thanked 0 Times in 0 Posts
The includes file has the code that closes the connection to the database.

It was my understanding that I need to do this before the end of the page if I redirect to another page. I didn't think that the connection would be closed.

Is there a "more correct" way to do this?

Thanks,
jakyra
  #7 (permalink)  
Old Sep 8th, 2003, 15:33
Highly Reputable Member
Join Date: Jul 2003
Location: Ipswich, UK
Posts: 690
Thanks: 0
Thanked 0 Times in 0 Posts
nope, your code wont stop running when it gets to a Response.Redirect, you can just open your connection at the top and close it at the bottom.
  #8 (permalink)  
Old Sep 8th, 2003, 15:47
Reputable Member
Join Date: Sep 2003
Location: USA
Posts: 112
Thanks: 0
Thanked 0 Times in 0 Posts
I found my error
*hangs head in shame*
I'm too embarassed to say what it was.

Thanks for taking the time to look through this.


jakyra (who's super embarassed)
  #9 (permalink)  
Old Sep 8th, 2003, 15:57
Reputable Member
Join Date: Sep 2003
Location: USA
Posts: 112
Thanks: 0
Thanked 0 Times in 0 Posts
Smokie,
Thanks for the info! I guess this is what comes of teaching yourself.

jakyra
  #10 (permalink)  
Old Sep 8th, 2003, 16:04
Highly Reputable Member
Join Date: Jul 2003
Location: Ipswich, UK
Posts: 690
Thanks: 0
Thanked 0 Times in 0 Posts
hey no problem, im self taught too
Closed Thread

Tags
bug

Thread Tools

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is On
HTML code is Off
Trackbacks are On
Pingbacks are On
Refbacks are On

Similar Threads
Thread Thread Starter Forum Replies Last Post
Can you find simonb Webforumz Cafe 9 Oct 18th, 2007 18:01
Where to find a designer? jonbcheshire Starting Out 2 Jul 25th, 2007 07:41
Find a post DregondRahl Webforumz Cafe 4 Jun 5th, 2007 12:40
Hi, I need help to find a host... Cat22 Hosting & Domains 13 Nov 15th, 2006 14:42


All times are GMT. The time now is 23:45.


Powered by vBulletin®
Copyright ©2000 - 2008, Jelsoft Enterprises Ltd.
Search Engine Friendly URLs by vBSEO 3.2.0 RC8
© 2003-2008 Webforumz.com : All Rights Reserved

1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43