Auto-creating a "link" table between 2 main tables (ex table EmployeeProject from Employee and Project tables)
Posted
by
user573382
on Stack Overflow
See other posts from Stack Overflow
or by user573382
Published on 2011-01-12T21:36:39Z
Indexed on
2011/01/12
21:54 UTC
Read the original article
Hit count: 89
Hello! I have these 2 tables, Medication containing: IDMedication, IDCategory, Name, and Supplier, containing: IDSupplier, Name. I want to automatically create a relationship table, MedicationSupplier, containing: IDMedication and IDSupplier as keys, Price, and Quantity. My idea was to have a main page where i request the following data: (Medication)Name, IDCAtegory, (Supplier)Name, Price, Quantity. I'm not sure if i'm doing the right thing here.
So this is what i'm receiveing in the .php where i do the insert:
$Denumire=$_POST['Denumire']; //Medication Name
$IDCategorie=$_POST['IDCategorie']; //IDCategory
$Nume=$_POST['Nume']; //Supplier Name
$Pret=$_POST['Pret']; //Price
$Stoc=$_POST['Stoc']; //Quantity
And this is my insert:
$q_produse = "INSERT INTO produse VALUES ('','$IDCategorie','$Denumire')";
$q_prodfurniz = "INSERT INTO produsfurnizor VALUES ('','$IDFurnizor','$Pret','$Stoc')";
mysql_query($q_produse) or die($error);
mysql_query($q_prodfurniz) or die($error);
mysql_close();
My main problem at the moment is that i don't know how to insert IDMedication in the relationship table. Any help / suggestions of improving my code would be greatly appreciated. Thanks!
© Stack Overflow or respective owner