terça-feira, 8 de agosto de 2023

Criar Tela de Login com Mysql em Delphi

 procedure TForm1.Button1Click(Sender: TObject);

var Username: string; Password: string; Connection: TMySQLConnection; Query: TMySQLQuery; begin // Get the username and password from the text boxes. Username := Edit1.Text; Password := Edit2.Text; // Create a new MySQL connection. Connection := TMySQLConnection.Create(nil); // Connect to the database. try Connection.Host := 'localhost'; Connection.Port := 3306; Connection.Database := 'my_database'; Connection.User := 'my_username'; Connection.Password := 'my_password'; Connection.Connect; // Create a new MySQL query. Query := TMySQLQuery.Create(nil); // Set the query. Query.SQL := 'SELECT * FROM users WHERE username = :username AND password = :password'; Query.ParamByName('username').Value := Username; Query.ParamByName('password').Value := Password; // Execute the query. Query.ExecSQL; // Check if the query was successful. if Query.RecordCount > 0 then begin // The login was successful. ShowMessage('Login successful!'); Close; end else begin // The login was unsuccessful. ShowMessage('Login failed!'); end; finally // Free the MySQL connection. Connection.Free; end; end; procedure TForm1.Button2Click(Sender: TObject); begin // Close the form. Close; end;

Nenhum comentário:

📌 Tela de Splash, Tela de Login e Tela Principal em Delphi: Aprendendo na Prática

  No desenvolvimento de sistemas, a experiência do usuário começa muito antes de utilizar as principais funcionalidades do software. Elemen...