Results 1 to 4 of 4

Thread: So how to write the part of login to the database with the sql command .

  1. #1
    Join Date
    Jan 2011
    Posts
    40
    Thanks
    5
    Qt products
    Qt4 Qt/Embedded
    Platforms
    Unix/X11 Windows

    Default So how to write the part of login to the database with the sql command .

    Qt Code:
    1. QString var_s_user,var_s_pass,var_s_sql;
    2. var_s_user=ui->lineEdit_user->text().trimmed();
    3. var_s_pass=ui->lineEdit_pass->text().trimmed();
    4. QSqlQuery query_cmd;
    5. var_s_sql="select username from user where username = " +var_s_user + " and password="+var_s_pass+";";
    6. query_cmd.exec(var_s_sql);
    To copy to clipboard, switch view to plain text mode 
    I have finished the connection to the database .And it could connect to the data normally.
    But I just cant solve the login part.So how to check if the username and password is right.
    I use the code QSqlRecord rec = query_cmd.record();to find out if there is a right username and password in the database.But it did not work .So anyone could give me some examples?

  2. #2
    Join Date
    Jan 2006
    Location
    Napoli, Italy
    Posts
    621
    Thanks
    5
    Thanked 86 Times in 81 Posts
    Qt products
    Qt3 Qt4
    Platforms
    Unix/X11 Windows

    Default Re: So how to write the part of login to the database with the sql command .

    When you use SELECT you must use QSqlQuery::next() to retreive records

    Qt Code:
    1. QSqlQuery query_cmd("select username from user where username = "
    2. + var_s_user + " and password="+var_s_pass);
    3. if (query_cmd.next()) {
    4. // Data found
    5. }
    To copy to clipboard, switch view to plain text mode 

    IN this case you can use QSqlQuery::first() instead of QSqlQuery::next() because you are intersted only on the presence of one record
    Last edited by mcosta; 4th February 2011 at 11:03. Reason: reformatted to look better
    A camel can go 14 days without drink,
    I can't!!!

  3. #3
    Join Date
    Jan 2011
    Posts
    40
    Thanks
    5
    Qt products
    Qt4 Qt/Embedded
    Platforms
    Unix/X11 Windows

    Default Re: So how to write the part of login to the database with the sql command .

    thankyou very much.If there is only the way you just mentioned .I am glad to hear that.

  4. #4
    Join Date
    Sep 2010
    Location
    Poland
    Posts
    112
    Thanks
    8
    Thanked 3 Times in 3 Posts
    Qt products
    Qt4
    Platforms
    Unix/X11 Windows Maemo/MeeGo

    Default Re: So how to write the part of login to the database with the sql command .

    I've got a question ?
    Why do you need checking the correction of username and pass ?
    I am just asking, because this thought is literally piercing through my brain and I can stop myself from asking
    My schedule makes my cry
    My works makes my laugh
    My life makes... oh...no....

Similar Threads

  1. Replies: 7
    Last Post: 20th October 2012, 13:44
  2. Replies: 2
    Last Post: 2nd November 2010, 05:15
  3. Replies: 1
    Last Post: 17th January 2010, 07:36
  4. Replies: 4
    Last Post: 14th July 2009, 03:27

Bookmarks

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •  
Digia, Qt and their respective logos are trademarks of Digia Plc in Finland and/or other countries worldwide.