| |||||||||
![]() |
|
|
«
Previous Thread
|
Next Thread
»
|
Thread Tools | Search this Thread | Display Modes |
|
#1
|
|||
|
|||
|
help with C++ and mysql
Greetings!
Im making a database program that can display the contents of a table, add entries and search for entries in the database (using mySQL). There are no problems in connecting to the dbase. The problem is displaying them. I get errors if I try to display the database contents in the edit boxes. It compiles fine and I am able to run the prrogram, but when I try to push the button that displays the contents of the database, i get errors. I am using WIN32 API (no MFC) and mySQL++. Ive look in the mySQL++ manuals but it only documents how to display the contents of a database using Windows Console. Hope someone can help me. Thanks and more power! |
|
#2
|
|||
|
|||
|
Am no expert with the win32 API so may not be able to help even if you provide more details but your description of the problem is quite unhelpful. If you could give some code samples and say what errors you are getting then it will help people on here figure out what the problem is.
-KM- |
|
#3
|
|||
|
|||
|
yeah ok.. here goes:
heres the main function: int APIENTRY WinMain(HINSTANCE hInst,HINSTANCE hPrevInst,LPSTR lpCmdLine,int nCmdShow) { frmMain.Create(hInst,0,0,1024,740,"Kanayunan Foundation",LoadIcon(hInst,MAKEINTRESOURCE(IDOK)),WndProc,tru e); StaticUser = frmMain.AttachWindow(hInst,"STATIC",422,300,80,20,"Username: ",NULL); StaticPass = frmMain.AttachWindow(hInst,"STATIC",422,330,80,20,"Password: ",NULL); EditUser = frmMain.AttachWindow(hInst,"EDIT",502,300,100,20,"",WS_BORDER); //Edit box for user input EditPass = frmMain.AttachWindow(hInst,"EDIT",502,330,100,20,"",WS_BORDER|ES_PASSWORD); // edit box for pass input CmdLogin = frmMain.AttachWindow(hInst,"BUTTON",477,370,80,30,"Login",NULL); //button frmMain.AddEvent(CmdLogin,eCLICK,CmdLogin_Click); frmMain.AddEvent(EditUser,eCHANGE,EditUser_Change) ; frmMain.Show(); MSG msg; while(GetMessage(&msg,0,0,0)) { TranslateMessage(&msg); DispatchMessage(&msg); } mysql_close(pConnect); return msg.wParam; } heres the function when the login button is pressed: int CmdLogin_Click() { //char test; //for testing password and surname occurence GetWindowText(EditUser, user, 20); //gets user input GetWindowText(EditPass, pass, 20);//gets user input //makes sure user inputted something if(GetWindowTextLength(EditUser) == 0) { ERR("Please enter your username!"); //void ERR(char *charmsg); custom function return 0; } if(GetWindowTextLength(EditPass) == 0) { ERR("Please enter your password!"); return 0; } pConnect = mysql_init(NULL); if(!(mysql_real_connect(pConnect,"localhost","test","","article1",0,NULL,0))) //error, quit the program { ERR("Failed to connect to Mysql."); return 0; } sprintf(query,"SELECT * FROM user WHERE Username = '%s' AND Password = '%s'",user,pass); mysql_query(pConnect,query); //query the database pResult = mysql_use_result(pConnect); while ((row = mysql_fetch_row(pResult))) {} sprintf(query,"%d", mysql_num_rows(pResult)); if(atoi(query) == 0) { ERR("Wrong User/Pass!"); return 0; } sprintf(query,"User %s has logged in!",user); Message(query); //void Message(char *message); custom function sprintf(query,"ID %s",row[2]); --->> heres the problem Message(query); ---->> also here ---other codes for closing mysql follows--- Now i want the user ID to be pasted on one of the edit boxes along wth other info, but I cant. It compiles fine and runs ok, but when it tries to display the othr info in the edit boxes a debug error appears (like when an application fails or hangs or when u forcibly close it)... something like..."This application has encoutnered some errors and needs to be closed."... then it prompts you if you want the error to be sent or not. Hope someone can help me. Thanks! |
![]() |
| Viewing: Dev Articles Community Forums > Programming > C/C++ Help > help with C++ and mysql |
| Thread Tools | Search this Thread |
| Display Modes | Rate This Thread |
|
|
|
|