Exit
  • Global community
    • Language:
      • Deutsch
      • English
      • Español
      • Français
      • Português
  • 日本語コミュニティ
    Dedicated community for Japanese speakers
  • 한국 커뮤니티
    Dedicated community for Korean speakers
0

Passing the ID of a record being added into another table

Enthusiast ,
Aug 05, 2006 Aug 05, 2006

Copy link to clipboard

Copied

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
TOPICS
Server side applications

Views

237
Translate

Report

Report
Community guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
community guidelines

correct answers 1 Correct answer

Enthusiast , Aug 06, 2006 Aug 06, 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.

Votes

Translate
Enthusiast ,
Aug 06, 2006 Aug 06, 2006

Copy link to clipboard

Copied

LATEST
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.

Votes

Translate

Report

Report
Community guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
community guidelines