Results 1 to 8 of 8

Thread: [Qt/Sql] SQL Authentification : what query execute ?

Hybrid View

Previous Post Previous Post   Next Post Next Post
  1. #1
    Join Date
    Mar 2008
    Location
    Kraków, Poland
    Posts
    1,540
    Qt products
    Qt4
    Platforms
    Unix/X11 Windows
    Thanked 284 Times in 279 Posts

    Default Re: [Qt/Sql] SQL Authentification : what query execute ?

    First of all in line 4 You are taking from database only one value (mdp) but in line 10 You are trying to read value number 2 from result. Lines 9 and 10 should looks like :
    Qt Code:
    1. if( query.first() )//position on first record. if false then SELECT returns nothing
    2. if(query.value(0).toString() == password->text())
    To copy to clipboard, switch view to plain text mode 

  2. The following user says thank you to Lesiok for this useful post:


  3. #2
    Join Date
    May 2013
    Posts
    5
    Qt products
    Qt4
    Platforms
    Windows
    Thanked 5 Times in 5 Posts

    Default Re: [Qt/Sql] SQL Authentification : what query execute ?

    Thanks you for your help, now, if pseudo AND pwd is correct, then it work. But, how to do for check for existing pseudo/ pwd in database, like any kind of authentication system, which query I need ?
    I've read that, in PHP, we need to use something like :

    Qt Code:
    1. <?php
    2. $req = $bdd->prepare("SELECT COUNT(*) FROM profil WHERE pseudo = :pseudo");
    3. $req->bindValue(':pseudo', $_SESSION['pseudo'], PDO::PARAM_STR);
    4. $req->execute();
    5. $nb = $req->fetchColumn();
    6. if($nb == 0)
    7. echo 'Pseudo not found';
    8. else
    9. // ...
    To copy to clipboard, switch view to plain text mode 

    But i don't know how to do in Qt.

  4. The following user says thank you to CR4SH for this useful post:


  5. #3
    Join Date
    Mar 2008
    Location
    Kraków, Poland
    Posts
    1,540
    Qt products
    Qt4
    Platforms
    Unix/X11 Windows
    Thanked 284 Times in 279 Posts

    Default Re: [Qt/Sql] SQL Authentification : what query execute ?

    Exactly the same as in PHP. After all, your main tool is here SQL and not PHP or C++.

  6. The following user says thank you to Lesiok for this useful post:


  7. #4
    Join Date
    May 2013
    Posts
    5
    Qt products
    Qt4
    Platforms
    Windows
    Thanked 5 Times in 5 Posts

    Default Re: [Qt/Sql] SQL Authentification : what query execute ?

    Yes but which function works the same as fetchColumn ? And what will be the type of $nb in case of Qt use ?

  8. The following user says thank you to CR4SH for this useful post:


  9. #5
    Join Date
    May 2013
    Posts
    5
    Qt products
    Qt4
    Platforms
    Windows
    Thanked 5 Times in 5 Posts

    Default Re: [Qt/Sql] SQL Authentification : what query execute ?

    Does anyone can help me ? I really need help to do this ...

  10. The following user says thank you to CR4SH for this useful post:


  11. #6
    Join Date
    Mar 2008
    Location
    Kraków, Poland
    Posts
    1,540
    Qt products
    Qt4
    Platforms
    Unix/X11 Windows
    Thanked 284 Times in 279 Posts

    Default Re: [Qt/Sql] SQL Authentification : what query execute ?

    Think a little. In the first email you know how to read a value from the database and now not ?
    Qt Code:
    1. QSqlQuery query;
    2. query.prepare("SELECT COUNT(*) FROM profil WHERE pseudo = :pseudo");
    3. query.bindValue(":pseudo", pseudo->text());
    4. if(query.exec())
    5. {
    6. query.first();
    7. if( query.value(0).toInt() == 0 )
    8. {//not found
    9. }
    10. else
    11. {//found
    12. }
    13. }
    To copy to clipboard, switch view to plain text mode 

  12. The following user says thank you to Lesiok for this useful post:


  13. #7
    Join Date
    May 2013
    Posts
    5
    Qt products
    Qt4
    Platforms
    Windows
    Thanked 5 Times in 5 Posts

    Default Re: [Qt/Sql] SQL Authentification : what query execute ?

    Thanks for your help, i finaly found how to do.

  14. The following user says thank you to CR4SH for this useful post:


Similar Threads

  1. Lua + C++ Function Execute
    By steadi in forum Newbie
    Replies: 1
    Last Post: 2nd December 2012, 17:44
  2. QSqlQuery does not execute
    By weixj2003ld in forum Qt Programming
    Replies: 7
    Last Post: 11th July 2012, 12:13
  3. Execute a .sql file with more than one query
    By ShadowBelmolve in forum Newbie
    Replies: 6
    Last Post: 19th August 2010, 16:48
  4. Can execute examples
    By gyre in forum Qwt
    Replies: 12
    Last Post: 26th February 2010, 08:51
  5. Replies: 2
    Last Post: 5th March 2008, 10:39

Tags for this Thread

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
  •  
Qt is a trademark of The Qt Company.