• Sign in to Neowin Faster!

    Create an account on Neowin to contribute and support the site.

  • 0
Sign in to follow this  

how to insert data in a table that has a foreign key of another table using c++ code ?


niniben    0

I have a Table Bailleur

IDB IDF nameb Adresseb telb


Where IDF is a foreign key to a table named Fournisseur

The Addresses Table:

IDF namef adressef telf 

This is a ONE-TO-N Relationship: Each Bailleur Has N fournisseur and each fournisseur has N bailleur

when i generated MPD I have a new table named fournir



i want to insert data in "bailleur" by typing the name of founisseur which is namef and the IDF of "fournisseur" will be inserted into column IDF of table "bailleur" all this using c++

here is what ive tried i alredy inserted data in table "Fournisseur"

here im using bailleur in a class called bailleur

int qstate1;
MYSQL_RES* res1;
void Bailleur::addb( MYSQL* conn){

string idf="";

cin.ignore(1, '\n');
cout << "Enter Nom du bailleur: ";
getline(cin, nomb);
cout << "Enter Adresse: ";
getline(cin, adresseb);
cout << "Enter tel : ";
getline(cin, telb);
cout<<"tapez le nom du fournisseur";

string insert_query = ""insert into bailleur (IDF,nomb, tel_b ,adresseb) 
   values (select IDF from fournisseur where nomf = '"+nomfou+"' 

const char* q = insert_query.c_str(); 

qstate1 = mysql_query(conn, q);

if (!qstate1)
    cout << endl << "Successfully added in database." << endl;

   cout << "Query Execution Problem!" << mysql_errno(conn) << endl;

i expect output to be successfully added in database but its alway query execution problem

sorry for the long post this is my first time posting in neowin

Share this post

Link to post
Share on other sites

0 answers to this question

Recommended Posts

There have been no answers to this question yet

Create an account or sign in to comment

You need to be a member in order to leave a comment

Create an account

Sign up for a new account in our community. It's easy!

Register a new account

Sign in

Already have an account? Sign in here.

Sign In Now
Sign in to follow this  

  • Recently Browsing   0 members

    No registered users viewing this page.