C/C++ Help
 
Forums: » Register « |  User CP |  Games |  Calendar |  Members |  FAQs |  Sitemap |  Support | 
 
User Name:
Password:
Remember me
 
Go Back   Dev Articles Community ForumsProgrammingC/C++ Help

Reply
Add This Thread To:
  Del.icio.us   Digg   Google   Spurl   Blink   Furl   Simpy   Y! MyWeb 
Thread Tools Search this Thread Display Modes
 
Unread Dev Articles Community Forums Sponsor:
  #1  
Old July 6th, 2004, 06:32 AM
lordcajen lordcajen is offline
Registered User
Dev Articles Newbie (0 - 499 posts)
 
Join Date: Jul 2004
Posts: 3 lordcajen User rank is Just a Lowly Private (1 - 20 Reputation Level) 
Time spent in forums: < 1 sec
Reputation Power: 0
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!

Reply With Quote
  #2  
Old July 6th, 2004, 08:54 AM
kode_monkey kode_monkey is offline
Contributing User
Dev Articles Newbie (0 - 499 posts)
 
Join Date: Jul 2003
Posts: 367 kode_monkey User rank is Just a Lowly Private (1 - 20 Reputation Level) 
Time spent in forums: 7 m 21 sec
Reputation Power: 6
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-

Reply With Quote
  #3  
Old July 6th, 2004, 11:00 AM
lordcajen lordcajen is offline
Registered User
Dev Articles Newbie (0 - 499 posts)
 
Join Date: Jul 2004
Posts: 3 lordcajen User rank is Just a Lowly Private (1 - 20 Reputation Level) 
Time spent in forums: < 1 sec
Reputation Power: 0
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!

Reply With Quote
Reply

Viewing: Dev Articles Community ForumsProgrammingC/C++ Help > help with C++ and mysql


Thread Tools  Search this Thread 
Search this Thread:

Advanced Search
Display Modes  Rate This Thread 
Rate This Thread:


Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

vB code is On
Smilies are On
[IMG] code is On
HTML code is Off
View Your Warnings | New Posts | Latest News | Latest Threads | Shoutbox
Forum Jump


Forums: » Register « |  User CP |  Games |  Calendar |  Members |  FAQs |  Sitemap |  Support | 
  
 





© 2003-2008 by Developer Shed. All rights reserved. DS Cluster 6 hosted by Hostway
Stay green...Green IT