Results 1 to 3 of 3

Thread: What 's Wrong with this Code

  1. #1
    Join Date
    May 2006
    Posts
    12
    Thanks
    0
    Thanked 0 Times in 0 Posts

    Question What 's Wrong with this Code

    I'm Trying this code to switch the user group , so this code select users with groups only if the user doesn't have a group or does'nt exist redirect it to another page
    Her is my code please check it
    Code:
    sql="select * from users,groups where users.user_id='"&id2&"' and users.group_id=groups.g_group_id"
    set rs=conn.Execute(sql)
    if rs.eof or rs("group_id")=null then 
    Response.Redirect("switch.asp?id="&session("session_id")&"&page=management")
    	else
    	dim group
    	group=rs("group_id")
    
    end if
    and It gives me this error message
    Error Type:
    (0x80020009)
    Exception occurred.

    Many Thax

  2. #2
    Join Date
    Oct 2004
    Posts
    4
    Thanks
    0
    Thanked 0 Times in 0 Posts

    Default

    Dude,
    you have a comma here ¬ instead of a period(full stop)
    sql="select * from users,groups where users.user

  3. #3
    Join Date
    Sep 2005
    Location
    India
    Posts
    1,627
    Thanks
    6
    Thanked 107 Times in 107 Posts

    Thumbs up Re:Whats Wrong with this code

    Hi

    Can you explain the usage of

    or rs("group_id")=null

    statement while checking the condition? what is the need for that statement. Since the SQL will return only records from users and groups table that have a proper master-detail relationship.

    If you have implemented the referential integrity constraints on your DB then there is very less chance of getting some orphan records too.

    My point is in your SQL statment you've used two conditions

    The first the userid field of users table must have the value stored in id2 variable.

    The second one is it will check the groupid field of users table to groupid field of groups table. Then how a groupid value which is null will come.

    When i removed that line the code worked correctly.

    Hope this will help you

    Regards

    Code Exploiter

Bookmarks

Posting Permissions

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