i'm reading in text values from 2 lineedit widgets and using the data from those to act as a log in system but i'm unable because the program is currently only checking if the Username is in the SQLITE database, i'm unsure why
My connection is done from
QSqlDatabase login = QSqlDatabase::addDatabase("QSQLITE");
login.setDatabaseName("/Users/Daniel/Dropbox/Stock_Control.sqlite");
if(!login.open())
ui->label->setText("Unable To Connect To Database");
My Log in code is below
static Home *home = new Home;
QSqlQuery query;
QString Username = ui->Username_lineEdit->text();
QString Password = ui->Password_lineEdit->text();
query.prepare("SELECT Login, Password FROM Program_account WHERE Login = '"+ Username +"' AND Password = '"+ Password +"'");
if(!query.exec())
{
qDebug() << "SQL QUERY Login:" << query.executedQuery();
qDebug() << "SQL ERROR Login:" << query.lastError();
}
else if(!query.first())
{
qDebug() << "SQL QUERY Login:" << query.executedQuery();
qDebug() << "SQL ERROR Login:" << query.lastError();
tries++;
int x = 10 - tries;
ui->label->setText("Incorrect Username or Password " + QString::number(x) + " tries until timeout");
}
else
{
qDebug() << "SQL QUERY Login:" << query.executedQuery();
qDebug() << query.value(0);
qDebug() << query.last();
qDebug() << "SQL ERROR Login:" << query.lastError();
tries = 0;
home->show();
close();
}
When query.value(1) is run the output is QVariant(Invalid), im guessing this is the source of my problem but i dont know why not how to fix it.
Thank you
Aucun commentaire:
Enregistrer un commentaire