I am creating a WinForm Registration Form and recently switched my entire code to remove SQL Injections I was getting. I can now register users to be stored in my database but I can not user that information to log on.
string constring = "datasource=127.0.0.1;port=3306;username=root;password=welcome";
string Query = "insert into userdatabase.users (userid, email, passone, passtwo, lastname, firstname) values(@userid,@email,@passone,@passtwo,@lastname,@firstname)";
MySqlConnection conDatabase = new MySqlConnection(constring);
MySqlCommand cmd = new MySqlCommand(Query, conDatabase);
cmd.Parameters.AddWithValue("userid", this.userid_txt.Text);
cmd.Parameters.AddWithValue("passone", this.passone_txt.Text);
try
{
conDatabase.Open();
cmd.ExecuteNonQuery();
MessageBox.Show("Welcome to iDSTEM!");
}
catch (Exception ex)
{
MessageBox.Show(ex.Message);
}
That is the code for my login button, I know that the AddWithValue is not what needs to be there but that is what I currently have to store the values and wanted to know what I should change it to.
Here is my code that stores my data into MySql.
string constring = "datasource=127.0.0.1;port=3306;username=root;password=welcome";
string Query = "insert into userdatabase.users (userid, email, passone, passtwo, lastname, firstname) values(@userid,@email,@passone,@passtwo,@lastname,@firstname)";
MySqlConnection conDataBase = new MySqlConnection(constring);
MySqlCommand cmd = new MySqlCommand(Query, conDataBase);
cmd.Parameters.AddWithValue("userid", this.userid_txt.Text);
cmd.Parameters.AddWithValue("email", this.email_txt.Text);
cmd.Parameters.AddWithValue("passone", this.passone_txt.Text);
cmd.Parameters.AddWithValue("passtwo", this.passtwo_txt.Text);
cmd.Parameters.AddWithValue("lastname", this.lastname_txt.Text);
cmd.Parameters.AddWithValue("firstname", this.firstname_txt.Text);
try {
conDataBase.Open();
cmd.ExecuteNonQuery();
MessageBox.Show("Welcome to iDSTEM!");
}
catch (Exception ex)
{
MessageBox.Show(ex.Message);
}
When I run the log in I receive
Fatal Error encountered during command execution
Thanks in advance for any helps or tips you are able to give me.