Skip to content
  • Categories
  • Recent
  • Tags
  • Popular
  • Users
  • Groups
  • Search
  • Get Qt Extensions
  • Unsolved
Collapse
Brand Logo
  1. Home
  2. Qt Development
  3. General and Desktop
  4. [solved][SQL] problem with extracting data
Forum Updated to NodeBB v4.3 + New Features

[solved][SQL] problem with extracting data

Scheduled Pinned Locked Moved General and Desktop
6 Posts 3 Posters 1.2k Views 2 Watching
  • Oldest to Newest
  • Newest to Oldest
  • Most Votes
Reply
  • Reply as topic
Log in to reply
This topic has been deleted. Only users with topic management privileges can see it.
  • K Offline
    K Offline
    killerman
    wrote on last edited by killerman
    #1

    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 ?

    1 Reply Last reply
    0
    • cybercatalystC Offline
      cybercatalystC Offline
      cybercatalyst
      wrote on last edited by
      #2

      Try getting more information by calling the lastError()-method.

      1 Reply Last reply
      0
      • K Offline
        K Offline
        killerman
        wrote on last edited by
        #3

        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
        
        1 Reply Last reply
        0
        • SGaistS Offline
          SGaistS Offline
          SGaist
          Lifetime Qt Champion
          wrote on last edited by
          #4

          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

          Interested in AI ? www.idiap.ch
          Please read the Qt Code of Conduct - https://forum.qt.io/topic/113070/qt-code-of-conduct

          1 Reply Last reply
          1
          • K Offline
            K Offline
            killerman
            wrote on last edited by
            #5

            Thanks a lot :)

            1 Reply Last reply
            0
            • SGaistS Offline
              SGaistS Offline
              SGaist
              Lifetime Qt Champion
              wrote on last edited by
              #6

              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 :)

              Interested in AI ? www.idiap.ch
              Please read the Qt Code of Conduct - https://forum.qt.io/topic/113070/qt-code-of-conduct

              1 Reply Last reply
              0

              • Login

              • Login or register to search.
              • First post
                Last post
              0
              • Categories
              • Recent
              • Tags
              • Popular
              • Users
              • Groups
              • Search
              • Get Qt Extensions
              • Unsolved