Answered
Passing the ID of a record being added into another table
I have a basic database with Candidates and Profiles in two
tables, along with an interlinking CandidateProfiles table.
I have a page here that I use to add new candidates, and hopefully attach any profiles for each candidate, that on submission will add the new Candidates details ot the Candidates table, and add any records to the CandidateProfiles table based on the ID of the newly created Candidate and whichever checkboxes are selected.
This is the Add Candidates page.
The current PHP code that I have for the checkboxes to add to the CandidateProfiles table is :
$sql = "INSERT INTO CandidateProfiles (CandidateID, ProfileID) VALUES ";
$ck = $_POST['ckbox'];
foreach ($ck As $GetIndex => $GetValue){
if ($GetValue=='on'){
$sql .= "('{$_POST['CandidateID']}', '$GetIndex'), ";
}
}
$sql = rtrim($sql," ,") ;
mysql_query($sql);
The line in bold is the error line 69.
It does however work in part - as new records do get added into the CandidateProfiles table with the correct profileIDs, but with a CandidateID of 0. So I just need to figure out how to change the CandidateID being added to the CandidateProfiles table from 0 to the ID of the new record being added....
Iain
I have a page here that I use to add new candidates, and hopefully attach any profiles for each candidate, that on submission will add the new Candidates details ot the Candidates table, and add any records to the CandidateProfiles table based on the ID of the newly created Candidate and whichever checkboxes are selected.
This is the Add Candidates page.
The current PHP code that I have for the checkboxes to add to the CandidateProfiles table is :
$sql = "INSERT INTO CandidateProfiles (CandidateID, ProfileID) VALUES ";
$ck = $_POST['ckbox'];
foreach ($ck As $GetIndex => $GetValue){
if ($GetValue=='on'){
$sql .= "('{$_POST['CandidateID']}', '$GetIndex'), ";
}
}
$sql = rtrim($sql," ,") ;
mysql_query($sql);
The line in bold is the error line 69.
It does however work in part - as new records do get added into the CandidateProfiles table with the correct profileIDs, but with a CandidateID of 0. So I just need to figure out how to change the CandidateID being added to the CandidateProfiles table from 0 to the ID of the new record being added....
Iain
