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 8113291
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 6, 20262026-06-06T02:46:47+00:00 2026-06-06T02:46:47+00:00

I am trying to use a PHP form (new.php) to update 2 MySQL tables

  • 0

I am trying to use a PHP form (new.php) to update 2 MySQL tables and retrieve information from a 3rd. The reason I need to use 3 tables is so that the information stored can be searched via another form (search.php) and, also, so that the information can be easily edited (edit.php).

New.php makes use of 4 text entry fields and, currently, 3 checkboxes (though this number will increase once I’ve gotten these 3 to work). The checkboxes act as “tags” that are used to describe articles that are entered into the database. So, a single entry in the database contains the following information:

Article Title, Article Organization, Access Date, Article URL, and Article Tag(s) (and there is also an id column for this table.

The title, organization, date, and url are all stored in a table named articles.

The tags are all stored in a table named tags (there are 85 of them). This table has 2 columns: id and tag_contents.

The 3rd table is a relation table (or maybe it’s called an “intersection table”?) called articles_tags with 2 columns: article_id and tag_id.

What new.php currently does is add the title, organization, date, and url to the articles table and, then, uses mysql_insert_id() to get the ID of that entry.

But, after that, I can’t figure out what I need to do with my checkboxes.

I have 3 checkboxes:

<input type="checkbox" name="articletags[]" value="science" id="articletags_0" />
<input type="checkbox" name="articletags[]" value="geology" id="articletags_1" />
<input type="checkbox" name="articletags[]" value="astronomy" id="articletags_2" />

I need to somehow use those checkboxes to make a relation with the article. So, for example, after inserting an article about rocks the form would look like:

Article Title: Great new rocks!
Article Organization: US Geology Assoc.
Access Date: 09/20/2012
Article URL: www.rocks.com

Science [X]    Geology [X]    Astronomy [ ] (note that the X marks a checked checkbox)

And, the database tables would look like this:

(table: articles) id | articletitle     | articleorganization | articledate | articleurl
                  13 | great new rocks! | US geology assoc.   | 9/20/2012   | www.rocks.com


(table: tags)     id | tag_contents
                   5 | geology
                   9 | science

(table: articles_tags)   article_id  | tag_id
                            13       |   5
                            13       |   9

Note that the tags table doesn’t change, it only stores the available tags and allows them to be referenced by the table articles_tags.

I can not figure this situation out and I’ve been hacking at it for a week now. For reference, the code for new.php is added below:

    <?php 
 }

 // connect to the database
 include('settings.php');

 if(count($articletags) > 0)
{
 $articletags_string = implode(",", $articletags);
}
 // check if the form has been submitted. If it has, start to process the form and save it to the database
 if($_SERVER['REQUEST_METHOD'] == 'POST')
 { 
 // get form data, making sure it is valid
 $articletitle = mysql_real_escape_string(htmlspecialchars($_POST['articletitle']));
 $articleorganization = mysql_real_escape_string(htmlspecialchars($_POST['articleorganization']));
 $articledate = mysql_real_escape_string(htmlspecialchars($_POST['articledate']));
 $articleurl = mysql_real_escape_string(htmlspecialchars($_POST['articleurl']));

 // check to make sure both fields are entered
 if ($articletitle == '' || $articleorganization == '')
 {
 // generate error message
 $error = 'ERROR: Please fill in all required fields!';

 // if either field is blank, display the form again
 renderForm($articletitle, $articleorganization);
 }
 else
 {
 // save the data to the database
 mysql_query("INSERT INTO articles SET articletitle='$articletitle',
      articleorganization='$articleorganization',
      articledate='$articledate',
      articleurl='$articleurl' ")

 or die(mysql_error()); 

 $article_id = mysql_insert_id();

 foreach( $POST_['articletags'] as $newtag )
{
   mysql_query('INSERT INTO articles_tags (article_id,tag_id) VALUES ($article_id, $newtag)');
}

 // once saved, redirect to success page
 header("Location:addsuccess.php");  
 }
 }
 else
 // if the form hasn't been submitted, display the form
 {
 renderForm('','','','','');
 }
?>
  • 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-06T02:46:48+00:00Added an answer on June 6, 2026 at 2:46 am
    <input type="checkbox" name="articletags[]" value="5" id="articletags_0" />Science
    <input type="checkbox" name="articletags[]" value="9" id="articletags_1" />Geology
    

    then in php

    foreach( $POST_['articletags'] as $newtag )
    {
       mysql_query('INSERT INTO articles_tags(article_id,tagID) VALUES( $idFromArticleInsert, $newtag )')
    }
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I am relatively new to MySQL and PHP and I have been trying to
I'm trying to create a new ftp account when a PHP form is processed.
I'm trying to use flexigrid to show results using the values from a form.
I'm trying to use php with mysql. basically i've an index page where user
I'm trying to use a PHP login form tutorial I found somewhere online, and
I am pretty new to PHP and I am trying to use the googlechartphplib...
I am trying to convert a paper form to a PHP form that will
I am trying to use This PHP Mail form, http://jemsmailform.com/ and I keep getting
I am trying to use PHP to fire hits at Google to track newsletter
I am trying to use PHP Curl to make the registrations of https://www3.gotomeeting.com/register/432624022 automatic.

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.