What's wrong with my IF statement?

Results 1 to 3 of 3

Thread: What's wrong with my IF statement?

  1. #1
    Join Date
    Dec 1969

    Default What's wrong with my IF statement?

    I&#039m doing a login page and it works correctly if someone enters their username<BR>and password correctly OR if someone enters<BR>their username correctly (By correctly I mean that the correct username and/or<BR>password is in the<BR>database).<BR><BR>But if both fields are left black or if both fields have incorrect info, then<BR>the page just comes up blank. It should be firing off the "ELSE" part if the IF<BR>statement but its just blank. So the connections to the database are working,<BR>its just my logic thats a bit off.<BR><BR>Heres my code:<BR><BR>&#060;%<BR><BR> if Request.Form("Password") = objrec("Password") and Request.Form("username")<BR>= objrec("username") then<BR> response.redirect ("index.asp")<BR> Else<BR><BR> response.write("We&#039re sorry, but that name is not found in the database" &<BR>"<BR>")<BR> response.write("If you&#039re a new user click &#060;a href=&#039register.asp&#039&#062;here&#060;/a&#062; to<BR>register" & "<BR>")<BR> response.write("Or you may go &#060;a href=&#039default.asp&#039&#062;back&#060;/a&#062; and try again")<BR>end if<BR><BR><BR>%&#062;<BR><BR>Anyone know what im doing wrong?<BR><BR>Thanks!<BR>Marc<BR><BR><BR>ps- I already know that I need to create a session - im just trying to get this part done first :)

  2. #2
    Join Date
    Dec 1969
    Los Angeles, CA

    Default RE: What's wrong with my IF statement?

    try using the cstr() function...sometimes that is the problem. <BR><BR>You MAY also want to response.write the values and check to see if they are the same

  3. #3
    Join Date
    Dec 1969

    Default Show more code..

    The problem is *not* in the code you are showing. It is almost surely in the QUERY you make of the DB.<BR><BR>I would bet that you query the DB by asking for the record that matches the user&#039s entered Request.Form("UserName"). Right?<BR><BR>Now consider what happens: IF the username entered *IS* found in the DB, then indeed your "objrec" will refer to the record for that user. But if the username is *NOT* found, *then* what does objrec refer to???? The answer: PROBABLY NOTHING. And what happens then? We can&#039t tell from the tiny fragment of code you are showing us.<BR><BR>HOWEVER: Why do all this????<BR><BR>If you do a DB query such as:<BR><BR> &nbsp; SQL = "SELECT * FROM UserTable WHERE UserName = &#039" & Trim(Request.Form("UserName") & "&#039" _<BR> &nbsp; &nbsp; &nbsp; &nbsp; & " AND Password = &#039" & Trim(Request.Form("Password") & "&#039"<BR> &nbsp; Set RS = yourConnection.Execute( SQL )<BR> &nbsp; If RS.EOF Then<BR> &nbsp; &nbsp; &nbsp; Response.Write "Sorry, I cannot find that username and password"<BR> &nbsp; &nbsp; &nbsp; ...<BR> &nbsp; Else<BR> &nbsp; &nbsp; &nbsp; Response.Redirect "index.asp" &#039 valid sign in!<BR> &nbsp; End If<BR><BR>See it? When you make the query that way, BOTH must match or the query will come back empty. And you are done. No "IF u=u and p=p" needed becuz the DB already did it for you!<BR><BR>Hey?<BR><BR>

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts