I have a database with two tables. There are four fields in table 1 that are duplicated in table 2. I would like to be able to enter that information only once and have it inserted into both tables. Is that possible?
For example, of the 12 fields in table 1, four are also in table 2. There are 13 other fields in table 2 that are entered separately. Below is the code for table 1. Can it be modified to also enter the four common fields into table 2 as well? The four common fields are progname, refurl, affurl and country.
The Insert acts only in one table at a time.
My question is what is the relationship between the two tables. If there isn't then you just need to run another query for the second table.
If however the two table are related via a unique key then I see no reason for duplicating data.
Just a tip:
include("dbinfo.inc.php");
$Fields=array('progname', 'parent', ...., 'notes'); //put all fields name in this array
$QStr="";
foreach($Fields as $field){
$val=isset($_POST[$field])?addslashes($_POST[$field]):"";
$QStr.=($QStr!="")?",":"";
$QStr.="'$val'";
}
$query = "INSERT INTO programs VALUES ($QStr)";
mysql_query($query)or die("Unable to insert data" . mysql_error());
The two tables are related by progname. One contains a list of affiliate programs, including hosting programs, and their related data. The other contains details about each hosting provider. I use output for the programs table on one website and the output from webhosts on another. Just need to include the referral url from programs with the data from webhosts.
Hope that makes sense.
In other words, match data by the common unique field progname and include the referral url from programs in output for webhosts.
Bookmarks