0

This is my error

You have an error in your SQL syntax; check the manual that corresponds to your MySql server version for the right syntax to use near 'Key) VALUES ('biaprot','4E0658D00F47D86D19A0E792E...' at line 1.

My code :

private bool validate_register(string user, string pass)
    {
        db_connection();
        MySqlCommand cmd = new MySqlCommand();
        cmd.CommandText = "INSERT INTO accounts (Username,Key) VALUES (@user,@pass)";
        cmd.Parameters.AddWithValue("@user", user);
        cmd.Parameters.AddWithValue("@pass", pass);
        cmd.Connection = connect;
        MySqlDataReader login = cmd.ExecuteReader();
        if (login.Read())
        {
            connect.Close();
            return true;
        }
        else
        {
            connect.Close();
            return false;
        }
    }
private void button1_Click(object sender, EventArgs e)
    {
        string user = textBox1.Text;
        string pass = GetWP(textBox3.Text);
        string pass2 = GetWP(textBox4.Text);

I use WhirlPool Hash to Encoded my password . Pls help me , thanks you

chris85
  • 23,846
  • 7
  • 34
  • 51
  • 1
    `key` is the reserved keyword in mysql it must be in `backtick` http://dev.mysql.com/doc/refman/5.7/en/keywords.html – Saty Dec 26 '15 at 06:39

1 Answers1

4

key is a mysql keyword, to use it as a column name you have to quote it in backticks

cmd.CommandText = "INSERT INTO accounts (Username,`Key`) VALUES (@user,@pass)";
Musa
  • 96,336
  • 17
  • 118
  • 137