Hi, I’m trying to select specific (not all) fields from two tables that already contain data (having being entered from a form) and insert them into a third table which currently has no data. These tables all belong to same database. I will eventually add if statements for insertation into the third table, so for example if userAge (from table1) <= ageLimit (from table 2) then that user gets inserted into the third table which is a table that will eventually list the approved members on a webpage. Does this make sense? Or is there an easier way to do this? It does seem a bit excessive to me to have to insert all the fields I want to make conditions for into a table. I was thinking of doing the condition statements on the php pages that insert data from the forms(1 php page for each) but I’ll need the data from BOTH tables.
Anyway, I’m already having trouble. I’m just trying to get data from the first table currenrly and it’s not going in! I don’t get any errors, it just doesn’t work. Also I’m uncertain of how to do it with a second table without overwriting anything. Maybe a simple join query? Can anybody help?
TABLE1:
userID
age
address
contact number
firstChoice
secondChoice
daysAvailable
maxHoursPerDay
healthProblems
TABLE 2:
activityID
instructor
ageLimit
numOfDays
hoursPerDay
suitablility
TABLE 3:
userID
activityID
firstChoice
secondChoice
daysAvailable
maxHoursPerDay
healthProblems
ageLimit
numOfDays
hoursPerDay
suitablility
completed
[php]mysql_connect("$host", “$username”, “$password”)or die(“cannot connect”);
mysql_select_db(“activities”)or die(“cannot select DB”);
$query = “SELECT userID, firstChoice, secondChoice, daysAvailable, maxHoursPerDay, healthProblems FROM table1”;
$result = mysql_query($query)or die(mysql_error());
while ($line = mysql_fetch_assoc($result)) {
mysql_query(“INSERT INTO table3 (userID, firstChoice, secondChoice, daysAvailable, maxHoursPerDay, healthProblems ) VALUES (’$line[userID]’, ‘$line[firstChoice]’, ‘$line[secondChoice]’, ‘$line[daysAvailable]’, ‘$line[maxHoursPerDay]’, ‘$line[healthProblems]’)”);
}[/php]