'SQLite3 WHERE clause C++
So I'm trying to make a login function that uses SQLite3, and what I want is the user to input his username and password and the program is going to search in the table for his username than his password and compare it, and if it matches he get access if don't he needs to input his credentials again. And this is how my function look right now:
void logIn(){
std::cout << "Username: "; std::cin >> user;
std::cout << "Password: "; std::cin >> psw;
//Open database
rc = sqlite3_open("Users.db", &db);
//create sql statement
sql = "SELECT Username FROM Users_info"
"WHERE Username='?';";
//Execute sql statement
sqlite3_prepare(db, sql, -1, &st, NULL);
sqlite3_bind_text(st, 1, user.c_str(), name.length(), SQLITE_TRANSIENT);
int rc = sqlite3_exec(db, sql, callback, (void*)data.c_str(), NULL);
//show SQL output
if (rc != SQLITE_OK) {
std::cout << "Error making Log In" ;
sqlite3_free(zErrMsg);
}
else
std::cout << "Log In succesfully" ;
sqlite3_close(db);
And as you can see in these lines I'm trying to use the WHERE clause
//create sql statement
sql = "SELECT Username FROM Users_info"
"WHERE Username='?';";
Because for example, in my table I have this "test" user and if I use this exact code in SQLite3 It's going to return the exact user that I want, and with that in mind, what I want is to somehow my program to compare the user input to the return of the sql code but I don't have any idea to do so. Hope this makes my doubt clear enough to be clarified.
Sources
This article follows the attribution requirements of Stack Overflow and is licensed under CC BY-SA 3.0.
Source: Stack Overflow
| Solution | Source |
|---|
