Ok so i have error 'Mysql.Data.Mysqlclient.MysqlException (0x80004005): Unknown column 'lotete' in 'field list' when im trying to insert a new value
C# code
string sql = "INSERT INTO `users` (`username`,`email`,`password`, `key`) VALUES (`lotete`, `test`, `xd`, `test2`)";
if (connection != null)
{
connection.Open();
MySqlCommand command = connection.CreateCommand();
command.CommandText = sql;
try
{
//command.Parameters.AddWithValue("@username", userName);
command.ExecuteNonQuery();
}
catch (System.Exception ex)
{
Debug.LogError("MySQL error: " + ex.ToString());
}
}
Mysql: http://prntscr.com/n0873w
You should use Parameters for command to prevent SQL Injection.
command.CommandText = "INSERT INTO users(username,email,password, key) VALUES(@username, @email, @password, @key)";
command.Parameters.AddWithValue("@username", "lotete");
command.Parameters.AddWithValue("@email", "test@test.com");
command.Parameters.AddWithValue("@password", "testtest");
command.Parameters.AddWithValue("@key", "test2");
User contributions licensed under CC BY-SA 3.0