Click here to Skip to main content
15,900,616 members
Please Sign up or sign in to vote.
0.00/5 (No votes)
See more:
i try to login with usertype and redirect to their pages e.g admin redirect to reports page and public user redirect to gallery..

when i try to login from admin username and password then nothing happened.. when click on login button page redirect login page and not redirect to reports page where as i want when admin login then they redirect to reports page

whereas when i login with public user name and password it redirect to gallery pages ..

here is the code

C#
protected void Button1_Click1(object sender, EventArgs e)
       {
           name = TextBox1.Text.Trim();
        pwd = TextBox2.Text.Trim();
        conn.Open();
     MySqlCommand cmd = new MySqlCommand("select ln.UName, ln.UPasword, ut.UserType_ID from login ln, UserType ut where ln.UName = '" + name + "' and ln.UPasword = '" + pwd + "' and ln.UserType_ID = ut.UserType_ID");
    cmd.Connection = conn;
    MySqlDataReader dr = cmd.ExecuteReader();
   if ( dr.HasRows )
    {
   dr.Read( );
   Session[ " UName" ] = dr[ 0 ].ToString( );

   Session[ " UPasword" ] = dr[ 1 ].ToString( );
   Session[ "UserType_ID" ] = dr[ 2 ].ToString( );


     }

   if (dr[2].ToString() == "1")
       {
          Response.Redirect( "View_Reports.aspx" );
        }
       else
      {
      Response.Redirect( "gallery.aspx" );
        }

        dr.Close();
        conn.Close();
    }


any help please?
Posted

I can think of two possibilities in this scenario

1)Either your query is not returning any rows,which means that you don't have the admin user in the database with the credentials you are entering.

2) There might be a redirection in the reports page.
 
Share this answer
 
Comments
Diya Ayesa 4-Oct-14 4:04am    
if query not returning any rows then how public user login and redirect to gallery page... ???
Diya Ayesa 4-Oct-14 4:05am    
and there is admin user in database.. and i cannot understand your second point
Diya Ayesa 4-Oct-14 4:34am    
?????????????????
What I am trying to say is

There might be users in the database but not sure if the admin user ,with the user and password that you are using is there.

Could you please check if there is any redirection in the View_Reports.aspx to the login page.
 
Share this answer
 
Comments
Diya Ayesa 4-Oct-14 5:02am    
there is a record exist with username and password and their usertype ID and i am also login from these user name and password...
if (dr[2].ToString() =="1")
{

Can you check the above if condition ,I think control might not be going in it.Can you check if the UserType is "1" in the database and there are no spaces.
 
Share this answer
 

This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)



CodeProject, 20 Bay Street, 11th Floor Toronto, Ontario, Canada M5J 2N8 +1 (416) 849-8900