[solved][SQL] problem with extracting data
-
Hi, I have a data base called "logingdata" and table "logingids" with columns: "id", "username" and "password" and I have a problem while extracting the data. Here is my code:
QString username, password; username = ui->lineLogin->text(); password = ui->linePassword->text(); QSqlQuery qry; if(qry.exec("SELECT * FROM employeeinfo WHERE username=" + username +" and password=" + password)){ int count = 0; while(qry.next()) count++; if(count == 1){ PoZalogowaniu zalog; zalog.exec(); this->hide(); } else{ QMessageBox::information(this, "Fail", "Wrong login or password"); return; } }
The qry.exec() returns "false". Where is a problem ?
When I changed it to a different table with identical structure except that a username and "password" were integers then it worked... Why ?
-
Try getting more information by calling the lastError()-method.
-
I typed in a login "killerman" and password"killerman" and i got an error:
Unknown column 'killerman' in 'where clause' QMYSQL: unable to execute query
-
Hi,
IIRC it should rather be something like:
QString("SELECT * FROM employeeinfo WHERE username='%1' and password='%2'").arg(username, password)
The quotes are missing from your original query
-
Thanks a lot :)
-
You're welcome !
Since you have it working now, please update the thread title prepending [solved] so other forum users may know a solution has been found :)