Skip to main content
Inspiring
August 5, 2006
Answered

Passing the ID of a record being added into another table

  • August 5, 2006
  • 1 reply
  • 285 views
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
This topic has been closed for replies.
Correct answer johngordon12
Just to say I've managed to get it doing pretty much what I needed it all to do - ie one page where new Candidates can be added to a Candidates table, submitted to a second page where Profiles can be attached to the Candidate just added - so the CandidateID of the newly added Candidate is passed through to the AddProfiles page where Profiles are added by selecting however many checkboxes.

1 reply

johngordon12AuthorCorrect answer
Inspiring
August 6, 2006
Just to say I've managed to get it doing pretty much what I needed it all to do - ie one page where new Candidates can be added to a Candidates table, submitted to a second page where Profiles can be attached to the Candidate just added - so the CandidateID of the newly added Candidate is passed through to the AddProfiles page where Profiles are added by selecting however many checkboxes.