help to resolve this ....
Untitled.jpg
#include "dialog.h"
#include "ui_dialog.h"
#define path_to_db "C:/Users/beethoven07/Documents/myDbVic/myDBvic.s3db"
ui(new Ui::Dialog)
{
ui->setupUi(this);
myDB.setDatabaseName (path_to_db);
if(checkFile.isFile())
{
if(myDB.open())
{
ui->lblStatus->setText("berhasil konek database");
}
}else
{
ui->lblStatus->setText("nda ta konek di database :(");
}
}
Dialog::~Dialog()
{
delete ui;
qDebug()<< "keluar dari database pada waktu program di matikan";
myDB.close();
}
void Dialog::on_btnClear_clicked()
{
ui->txtPassword->setText("");
ui->txtUsername->setText("");
}
void Dialog::on_btnLogin_clicked()
{
username = ui->txtUsername->text();
password = ui->txtPassword->text();
if(!myDB.isOpen()) {
qDebug() << "No connection to DB :(";
return;
}
if(qry.exec("SELECT username, password, Role FROM loginform WHERE username='" + username +
"\' AND password=\'" + password + "\'"))
{
if(qry.next())
{
ui->lblStatus ->setText("username dan password benar");
QString msg
= "username = " +qry.
value(0).
toString() + "\n" + "password = " +qry.value(1).toString() + "\n" +
"role = " +qry.value(2).toString();
} else {
ui->lblStatus->setText("Sala Password atau username bego");
}
}
}
#include "dialog.h"
#include "ui_dialog.h"
#define path_to_db "C:/Users/beethoven07/Documents/myDbVic/myDBvic.s3db"
Dialog::Dialog(QWidget *parent) :
QDialog(parent),
ui(new Ui::Dialog)
{
ui->setupUi(this);
myDB = QSqlDatabase::addDatabase ("QSQLITE");
myDB.setDatabaseName (path_to_db);
QFileInfo checkFile (path_to_db);
if(checkFile.isFile())
{
if(myDB.open())
{
ui->lblStatus->setText("berhasil konek database");
}
}else
{
ui->lblStatus->setText("nda ta konek di database :(");
}
}
Dialog::~Dialog()
{
delete ui;
qDebug()<< "keluar dari database pada waktu program di matikan";
myDB.close();
}
void Dialog::on_btnClear_clicked()
{
ui->txtPassword->setText("");
ui->txtUsername->setText("");
}
void Dialog::on_btnLogin_clicked()
{
QString username, password;
username = ui->txtUsername->text();
password = ui->txtPassword->text();
if(!myDB.isOpen()) {
qDebug() << "No connection to DB :(";
return;
}
QSqlQuery qry;
if(qry.exec("SELECT username, password, Role FROM loginform WHERE username='" + username +
"\' AND password=\'" + password + "\'"))
{
if(qry.next())
{
ui->lblStatus ->setText("username dan password benar");
QString msg = "username = " +qry.value(0).toString() + "\n" +
"password = " +qry.value(1).toString() + "\n" +
"role = " +qry.value(2).toString();
QMessageBox::warning(this, "Login berhasil", msg);
} else {
ui->lblStatus->setText("Sala Password atau username bego");
}
}
}
To copy to clipboard, switch view to plain text mode
do i did something mistake with this code?
thanks....
Bookmarks