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

if statement and trim 3

Status
Not open for further replies.

evr72

MIS
Dec 8, 2009
265
0
0
US
I am trying to trim two fields, but I don't think I am doing it correctly

Code:
if trim(rs("password")) = Passwordtx then
		trim(Session("Username")) = Usernametx
		Response.Redirect(RS("weekly"))

any advice is greatly appreciated

 
> trim(Session("Username")) = Usernametx

Trim() returns a value without leading or trailing spaces, so it doesn't not belong on the left side of the Equals sign. If you want your session variable set to the value of "Usernametx" without leading or trailing spaces, use this:

Session("Username") = Trim(Usernametx)
 
hmmm still not functioning the right way
this page verifies that the user name and password are correct and re-directs the user to the user page
Code:
	'Save the entered username and password
	Usernametx = Request.Form("txtUsername")	
	Passwordtx = Request.Form("txtPassword")

	'Build connection with database
	set conn = server.CreateObject ("ADODB.Connection")		
	conn.Open "DSN=mydsn;UID=user;PWD=mypassword"
	set rs = server.CreateObject ("ADODB.Recordset")		
	'Open record with entered username
	rs.Open "SELECT * FROM mydb where trim(username)='"& Usernametx &"'", conn, 1 
	 Response.Cookies("ValidUser") = Validated
	'If there is no record with the entered username, close connection
	'and go back to login with QueryString

	

	
	
	If rs.recordcount = 0 then
		rs.close
		conn.close
		set rs=nothing
		set conn=nothing
		Response.Redirect("login.asp?login=namefailed")
	end if
	
	'If entered password is right, close connection and open mainpage
	if trim(rs("password")) = Passwordtx then
		Session("Username") = Usernametx
		Response.Redirect(RS("mypage.asp"))

	'If entered password is wrong, close connection 
	'and return to login with QueryString
	else
		rs.Close
		conn.Close
		set rs=nothing
		set conn=nothing
		Response.Redirect("login.asp?login=passfailed")
	end if

 
... but in some cases it is wise to do this for the password check:

Code:
if trim(rs("password")) = trim(Passwordtx) then
       ' Assign trimmed value to session variable:
        Session("Username") = trim(Usernametx)


 
> hmmm still not functioning the right way
Ummmm you will have to be a little more specific...
 
You are working with trimmed fields obviously, so why not start with:

Code:
Usernametx = trim(Request.Form("txtUsername")    )
Passwordtx = trim(Request.Form("txtPassword"))

or you need an explicit trim in the SQL too:

Code:
"SELECT * FROM mydb where trim(username)='"& trim(Usernametx) &"'", conn, 1

?
 
What type of database are you using? Access, Microsoft SQL Server, Oracle, MySQL, etc...

-George

"The great things about standards is that there are so many to choose from." - Fortune Cookie Wisdom
 
DB2

I think I need to use the trim() without quotes

Thank you all!!!!
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top