So I am trying to redirect each user based on their role I have user and admin both login from the same page, but in my case it only authenticates the user but not the admin. it displays my "you have entered invalid username or password" message. Any thoughts. Thanks
here is my code
protected void Button1_Click(object sender, EventArgs e)
{
con.Open();
SqlCommand cmd = con.CreateCommand();
cmd.CommandType = CommandType.Text;
cmd.CommandText = "select * from registration where email='"+ TextBox1.Text+"' and password='"+TextBox2.Text+"'";
cmd.ExecuteNonQuery();
DataTable dt = new DataTable();
SqlDataAdapter da = new SqlDataAdapter(cmd);
da.Fill(dt);
tot = Convert.ToInt32(dt.Rows.Count.ToString());
if (tot > 0)
{
if (Session["checkoutbutton"] == "yes")
{
Session["user"] = TextBox1.Text;
Response.Redirect("update_order_details.aspx");
}
else
{
Session["user"] = TextBox1.Text;
Response.Redirect("order_details.aspx");
}
}
else
{
Label1.Text = "Invalid email or password";
}
con.Close();
con.Open();
SqlCommand cmd1 = con.CreateCommand();
cmd1.CommandType = CommandType.Text;
cmd1.CommandText = "select * from admin_login where username='" + TextBox1.Text + "' and password='" + TextBox2.Text + "' ";
cmd1.ExecuteNonQuery();
DataTable dt1 = new DataTable();
SqlDataAdapter da1 = new SqlDataAdapter(cmd);
da1.Fill(dt);
i = Convert.ToInt32(dt.Rows.Count.ToString());
if (i == 1)
{
Session["admin"] = TextBox1.Text;
Response.Redirect("add_product.aspx");
}
else
{
Label1.Text = "you have entered invalid username or password";
}
con.Close();
}