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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 5, 20262026-06-05T23:20:02+00:00 2026-06-05T23:20:02+00:00

I have a MySQL database called csftdb and in that database there exists 1

  • 0

I have a MySQL database called csftdb and in that database there exists 1 table: articles.

I also have a series of PHP forms that can add, edit, and delete entries to/from the table within the database.

Now, however, I’m attempting to add search functionality and have found that the single-table method is insufficient.

The table is laid out thus:

id - articletitle - articleorganization - articledate - articleurl - articletags

One of the PHP forms is a search form and it works except when the tags come into play, for example:

Say there are 3 articles in the database:

01 - My first article - Article Corp. - 05/28/2010 - www.articlecorp.com/article1 - php, html
02 - My second article - Article Corp. - 08/11/2012 - www.articlecorp.com/article2 - asp, html
03 - My third article - Article Corp. - 12/22/2011 - www.articlecorp.com/article3 - c++, html

And then I have a search form with fields for Title, Organization, Date, URL, and Tag(s). I am able to search “My first article” in the Title field and only retrieve the 1st entry, but I can also search “article” in the Title field and it would retrieve all 3 entries. This is the desired behavior. Further, I can search “article” in the Title field and “Article Corp.” in the Organization field and it would only show entries that match that set (so, if there were other organizations that also had the word “article” in their article titles, those organizations would not show up in the results.) This is also desired behavior.

However, if I were to search “Article” in the title field, and then “php, asp, c++” in the Tag(s) field, my search would return no results. This is not the desired behavior. In this case, the “tags” are supposed to allow a more fine level of granularity with the search results.

So I could conceivably have a thousand articles, all with the exact same Title etc. information but with different combinations of tags and I could search for the tags and retrieve all of the articles with just those tags applied.

To that end, I have created 2 new tables in my database and altered the original one such that my tables are now:

articles:
id | articletitle | articleorganization | articledate | articleurl


tags:
id | tags

and

articles_tags:
article_id | tag_id

I also have the following PHP form which is modified from the original form:

        <?php
     function renderForm($articletitle, $articleorganization, $articledate, $articleurl, $articletags )
     {
     ?>
    . . .
      <div class="content">
            <div id="stylized" class="myform">
          <form id="form" name="form" action="" method="post">
            <h1>Create a new entry in the database</h1>
            <table width="100%" border="0" cellpadding="6">
              <tr>
                <td colspan="2"><legend>Article details</legend></td>
              </tr>
              <tr>
                <td width="20%" align="right"><span class="field">Article Title:</span></td>
                <td width="80%" align="left"><span class="field">
                  <input name="articles.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 $articles.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="articles.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 $articles.articleurl; ?>" size="50"/>
                </span></td>
              </tr>
              <tr>
                <td align="right"><span class="field">Article Tags:</span></td>
                <td align="left"><span class="field">
                <input name="articletags" type="text" value="<?php echo $tags.articletags; ?>" size="50"/>
                </span></td>
              </tr>
            </table>
            <footer><input type="submit" name="submit" value="Add this Article"></footer>
            </form>
        </div>
        . . .
    </body>
    </html>
    <?php 
     }

     . . .
      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']));

     . . .

     mysql_query("INSERT articles SET articletitle='$articletitle', articleorganization='$articleorganization', articledate='$articledate', articleurl='$articleurl', articletags='$tags.articletags' ")
     or die(mysql_error()); 


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

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

However I can’t seem to get the information to store into my 2nd table and, thus, I can’t get my relations to work.

I’ve been looking at this all day and can not figure it out.

  • 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-05T23:20:03+00:00Added an answer on June 5, 2026 at 11:20 pm

    You’ll need to add a couple more INSERT queries to get this to work properly.

    if (mysql_query ("INSERT INTO `articles` SET
      `articletitle` = '$articletitle',
      `articleorganization` = '$articleorganization',
      `articledate` = '$articledate',
      `articleurl` = '$articleurl'")) {
    
      $article_id = mysql_insert_id();
    }
    
    $tags = split (' ', $_POST['articletags']);
    foreach ($tags as $tag) {
      // check if tag exists in tag table and get id, if not, insert it and get mysql_insert_id()
      // then insert article_id with tag_ids into your articles_tags table
    }
    

    This is rough but its the idea. Also, if I recall correctly “split” is depreciated so you’ll want to find another option.

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

Sidebar

Related Questions

I have a MYSQL database table called 'wp_quotes' with a field that contains a
I am working in PHP/MySQL. I have a table in my database called hourly
I have a table in MySQL database. In that table there is a text
I have a table in my MySQL database called 'children'. In that table is
I have a MySQL database table called Participant that looks something like this: (idParticipant)
I have a MySQL Database. In it's table is a field called 'itm_name' I'm
I have names stored in my mysql database i created a table called users
So, I am modeling a database using MySQL Workbench. I have a table called
I have a MySQL database table called submission with a field called points with
I have a MySQL database with a table called subm_items The table contains the

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.