Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • SEARCH
  • Home
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 7960641
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 4, 20262026-06-04T04:48:48+00:00 2026-06-04T04:48:48+00:00

I have constructed a array that gets the information from checkboxes. This is working

  • 0

I have constructed a array that gets the information from checkboxes. This is working fine, however i require a second input where the id of a second table is placed next to the array data. For example, when a user inputs data to my php form, it generates a id on one table, whereas my checkboxes are saved to a second. I want when the user selects the checkbox, the id is placed here. The problem i have is that i dont know just where to put this data.

$insertSQL2 = "INSERT INTO Project_course (Proj_id Cour_id) SELECT Course_id FROM courses WHERE 
Code IN (";
foreach ($_POST['CheckboxGroup1'] as $Q){
$Q = mysql_real_escape_string($Q);
$insertSQL2.= "'$Q', ";
 } 
 $insertSQL2 = rtrim($insertSQL2, ", ");
$insertSQL2 .= ")";

Proj_id is where the id need to go, while Cour_id is where it checkboxes are saved. Aswell as this, it needs to happen simultaneously as the relationship in the mysql table means that one column cannot be blank.

I know this was long winded, so any help will be gratefully accepted

  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-06-04T04:48:49+00:00Added an answer on June 4, 2026 at 4:48 am

    If I understand your question correctly, the form first saves project data, and then – some course data connected with this project.

    BTW – first thing I suggest is to leave pure mysql_* functions in favour of PDO. But this is offtopic.

    Anyway – first you probably run something like

    $sql = "INSERT INTO project (col1, col2) VALUES (blah1, blah2)";
    mysql_query($sql)
    

    Then you can check the new project ID simply by invoking

    $projectID =  mysql_insert_id();
    

    And then something like

    foreach ($_POST['CheckboxGroup1'] as $key => $val)
    {
        $_POST['CheckboxGroup1'][$key] =  mysql_real_escape_string($val);
    }
    $sql = "INSERT INTO project_course(project_id, course_id) SELECT ".$projectID.", course_id FROM courses WHERE code IN (".implode(", ", $_POST['CheckboxGroup1']).")";
    

    UPDATE – if you already have a project in your project table, you may get project ID in several manners. For example by using SELECT project_id FROM project ORDER BY project_id DESC LIMIT 1.

    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I have a multi-dimensional array that looks like this: The base array is indexed
I have a pre-constructed array created from some test data as I have not
I have a class that contains an array. I want this array to be
I have a header which I constructed like this: <header class=top> <a href=> <span
Hi I have a question about this pointer, when an object is constructed, when
I am writing an application to monitor various information coming back from an array
It says that in my array that I have gone over the index. My
I have a MySQL query that fetches a numeric value VARCHAR (20) from a
I have a a class that has an integer array property and I am
I have previously constructed an array manually, e.g.: <?php $noupload = array('nick', 'cliff'); ?>

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.