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

  • Home
  • SEARCH
  • 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 8126519
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 6, 20262026-06-06T07:10:35+00:00 2026-06-06T07:10:35+00:00

My goal is to create an entry form (addnew.php) that will allow me to

  • 0

My goal is to create an entry form (addnew.php) that will allow me to later edit the entries made by using a different form (edit.php).

Currently addnew.php makes use of a few text fields and 2 checkboxes and what I’m attempting to do is to insert the information from the forms into a MySQL database. The information from the text fields is inserted into one table and the information from the checkboxes is inserted into a different table.

Now, though, I’m trying to use a 3rd table (if necessary) to make an intersection table that will allow me to use the same format used in addnew.php in the edit form.

So, in other words, addnew.php will have some text fields and check boxes and so will edit.php, the difference being that edit.php will have the information filled in and, in the case of the check boxes, they will be checked and the user will have the option to check more boxes or to uncheck already checked boxes.

The three tables that I have right now are:

articles:
id - articletitle - articleorganization - articledate - articleurl

tags:
id - tag_contents

articles_tags:
id - article_id - tag_id

And the code for addnew.php is:

    <?php
 function renderForm($articletitle, $articleorganization, $articledate, $articleurl, $articletags )
 {
 ?>
. . .
            <td width="20%" align="right"><span class="field">Article Title:</span></td>
            <td width="80%" align="left"><span class="field">
              <input name="articletitle" type="text" value="<?php echo $articletitle; ?>" size="50"/>
            </span></td>
          </tr>
          <tr>
            <td align="right"><span class="field">Article Author:</span></td>
            <td align="left"><span class="field">
              <input name="articleorganization" type="text" value="<?php echo $articleorganization; ?>" size="50"/>
            </span></td>
          </tr>
          <tr>
            <td align="right"><span class="field">Access Date:</span></td>
            <td align="left"><span class="field">
              <input name="articledate" type="text" value="MM/DD/YYYY" size="50"/>
            </span></td>
          </tr>
          <tr>
            <td align="right"><span class="field">Article URL:</span></td>
            <td align="left"><span class="field">
            <input name="articleurl" type="text" value="<?php echo $articleurl; ?>" size="50"/>
            </span></td>
          </tr>
          <tr>
            <td align="right"><span class="field">Article Tags:</span></td>
            <td align="left"><span class="field">
              <input type="checkbox" name="articletags[]" value="geology" id="articletags_0" />
              <input type="checkbox" name="articletags[]" value="astronomy" id="articletags_1" />
            </span>
            </td>
          </tr>
          <tr>
            <td colspan="2" align="center" valign="middle"><input type="submit" name="submit" value="Add this Article" /></td>
          </tr>
        </table>
        . . .
</html>
<?php 
 }


 include('settings.php');

 if(count($articletags) > 0)
{
 $articletags_string = implode(",", $articletags);
}

 if($_SERVER['REQUEST_METHOD'] == 'POST')
 { 

 $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']));
 $articletags = implode(',', $_POST['articletags']);

 if ($articletitle == '' || $articleorganization == '')
 {

 $error = 'ERROR: Please fill in all required fields!';


 renderForm($articletitle, $articleorganization);
 }
  else
 {

 mysql_query("INSERT INTO articles SET articletitle='$articletitle',
      articleorganization='$articleorganization',
      articledate='$articledate',
      articleurl='$articleurl' ")

$article_id = mysql_insert_id();

mysql_query("INSERT INTO tags SET articletags='$articletags' ");

$tag_id = mysql_insert_id();

mysql_query("INSERT INTO articles_tags SET article_id='$article_id',
      tag_id='$tag_id' ")


 or die(mysql_error()); 

 header("Location:addsuccess.php"); 
 }
  }
    else

  {
   renderForm('','','','','');
  }
?>

What I’m now having trouble with is figuring out exactly what to do next (after the 2nd INSERT). I know that I need to set up a relationship, but I can’t for the life of me figure out how to do that.

I’m assuming I need to store the tags in the tags table? But if that’s the case, how do I get their ID and insert them as a tag to the article?

Any help is greatly appreciated.

  • 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-06T07:10:37+00:00Added an answer on June 6, 2026 at 7:10 am

    If you are decided on this schema, you should be using the articles_tags table as a relationship between entries in the articles and the tags tables (1..*). This means that there will be multiple entries in the articles_tags table with the same article_id and a different tag_id for each tag associated with a given article.

    Alternatively, you could just keep reference to which article a tag belongs to by adding an article_id field to your tags table.

    Example:

    articles      |        tags          |        articles_tags
    id  title         id  tag_text              a_t_id   a_id   t_id
    4  Title1         8 Tagblahblah              1        4      8
    5  title2         9  tagccccc                2        4      9
                                                 3        5      8
    

    So these articles_tags entries mean that article with id 4 has tags with id’s 8 & 9. Tag 8 is also used for article id 5.

    This is the standard way in SQL to deal with a many to many relationship (*..*).

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

Sidebar

Related Questions

Goal: create webservice that will query database and return rows, then pass it to
My goal is to create an executable that will start a shadow copied application.
I'm trying to setup a server at www.domain.com that will allow me to create
My goal are to create a module that holds a listview with entries of
Duplicate: PHP validation/regex for URL My goal is create a PHP regex for website
My goal is to create an efficient structure to store the most relevant entries
My goal is to create a Web Service client that runs in a standalone
My goal is to create a reusable Attached Behavior for a FlowDocumentScrollViewer, so that
My goal is to create a map of maps so that I can retrieve
High Level Goal: Create a single Maven Web Application project that can be used

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.