Connecting c++ using mysql

Hi all
I'm creating application which user input has to be inserted into mysql table through variables

So i'm just providing that instance of code ....so just help me out.


int get_basic_info() //defining function to getting a student's basic information
{
student_basic_info: //creating label for goto statement if user didn't enter the basic info it will repeat itself

cout<<"Enter student's name\n"<<"Enter student's enrollment no\n"<<"Enter student's branch\n";
cin>>student_name>>enroll_no>>student_branch;

cout<<"Student name :"<<student_name<<"\n";
cout<<"Student roll no :"<<enroll_no<<"\n";
cout<<"student branch :"<<student_branch<<"\n";

MYSQL *connect; //creating mysql connect pointer
connect=mysql_init(NULL);
if (!connect)
{
cout<<"MySQL Initialization failed";
return 1;
}
connect=mysql_real_connect(connect, "localhost", "root", "wildstone" ,
"student" ,0,NULL,0);
if (connect)
{
cout<<"\n\n";
cout<<"connected to database\n";
}
else
{
cout<<"\n";
cout<<"connection failed\n";
}

int query_state;

query_state=mysql_query (connect,"insert into student_record values('student_name','enroll_no','student_branch');"); //inserting values here but its not working.......

//


if(query_state)
{
cout<<"\n";
cout<<"Student's basic information successfully saved in database";
}
else
{
cout<<"\n";
cout<<"Problem occuring while saving information into database";
}






if(student_name!=0 && enroll_no!=0 && student_branch!=0)
{
cout<<"\n\n";
cout<<"Thank you for entering the basic information\n";
}





and here is the output of mysql table



mysql> select * from student_record;
+----+--------------+-----------+----------------+
| id | name | roll_no | branch |
+----+--------------+-----------+----------------+
| 1 | student_name | enroll_no | student_branch |
| 2 | student_name | enroll_no | student_branch |
| 3 | student_name | enroll_no | student_branch |
| 4 | student_name | enroll_no | student_branch |
+----+--------------+-----------+----------------+
4 rows in set (0.00 sec)



means it just saving the student_name in the column where student_name is the variable which has different value every time...


please help
thanx in advance

Topic archived. No new replies allowed.