Liean
Liean
CC#
Created by Liean on 12/11/2024 in #help
incorrect even if its the same data from the database
im doing the login form for my system but even if i input the correct record from my database the messagebox i created always say its incorrect. here's the code for the button string user = idtb.Text; string password = ptb.Text; using (MySqlConnection con = new MySqlConnection(connector)) { con.Open(); string query = "SELECT firstname,usertype FROM userinformation WHERE username = @usernameee AND password = MD5(@passworddd)"; MySqlCommand cmd = new MySqlCommand(query, con); cmd.Parameters.AddWithValue("@usernameee", idtb.Text.Trim()); cmd.Parameters.AddWithValue("@passworddd", ptb.Text.Trim()); try { using (MySqlDataReader reader = cmd.ExecuteReader()) { if (reader.Read()) { string fn = reader.GetString("firstname"); string type = reader.GetString("usertype"); MessageBox.Show($"Welcome,{fn}!","Login Succesful"); if (type == "admin") { adminform adminform = new adminform(); adminform.Show(); } else if (type == "banker") { bankerform bankerform = new bankerform(); bankerform.Show(); } else if (type == "user") { userform userform = new userform(); userform.Show(); } } else { MessageBox.Show("Incorrect User Id/Password", "Login Failed"); } } } catch (Exception ex) { MessageBox.Show($"An error occurred: {ex.Message}", "Error", MessageBoxButtons.OK, MessageBoxIcon.Error); }
11 replies