Member Avatar

I'm trying to do the following:

  1. get username typed into the userField
  2. make a SEARCH mysql_query with the username as a variable

I'm having a hard time getting past phase 2 since mysql_query takes a const char* as the query string, and I can only get username as char* or wchar_t*

I'm also compiling in unicode.

My code for now:

void mysql_connect(HWND hLoginWnd) {

MYSQL *con, mysql;
MYSQL_RES *res;
mysql_init(&mysql);

mysql_options(&mysql, MYSQL_SET_CHARSET_NAME, "utf8");

mysql_real_connect(&mysql, "localhost", "root", "", "treenitaulu", 3306, NULL, 0);

char name[512], pass[512];
int lenUser = SendMessage(userField, WM_GETTEXT, 512, (LPARAM)name);
int lenPass = SendMessage(passField, WM_GETTEXT, 512, (LPARAM)pass);

if(lenUser > 0 && lenPass > 0) {

    std::string query = "SELECT pass FROM users WHERE name='" + std::string(name) + "'";

    mysql_query(&mysql, query.c_str());

}

}

What should I do?

I don't understand -- what does line 19 have to do with username? At line 19 the contents of query already contains the user name.