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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 5, 20262026-06-05T22:15:56+00:00 2026-06-05T22:15:56+00:00

I have a PHP form with 4 text fields and 2 checkboxes. The checkboxes

  • 0

I have a PHP form with 4 text fields and 2 checkboxes. The checkboxes are “tags” that can be applied to the articles that are input using the text fields.

For example:

Information:

Title – Defining intransitive relationships of the migratory birds of South America

Author – Author. S. Wellington

Access Date – 19/06/2012

URL – http://www.wellington.org/articles/birds/def-int-rel-mig-bird-s-amer.pdf

Tags:

Birds[X] South America[X]

In this case both of the checkboxes would be checked, because the article pertains both to birds and South America.

I have a database with 3 tables in it:

articles: id – articletitle – articleorganization – articledate – articleurl

tags: id – tag_content

articles_tags: article_id – tag_id

Currently, my form can insert the article information into the articles table using:

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

and then, I can use $article_id = mysql_insert_id(); to get the id that would be inserted into the articles_tags table.

But after that I am totally stumped.

I need to somehow loop over the checkboxes:

<input type="checkbox" name="articletags_birds" value="Birds" id="articletags_0" />
<input type="checkbox" name="articletags_southamerica" value="South America" id="articletags_1" />

but I have no idea how I should be doing that.

  • 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-05T22:15:57+00:00Added an answer on June 5, 2026 at 10:15 pm
    if ($_POST['articletags_birds'] == 'on')
    {
        mysql_query("INSERT INTO tags SET id='$article_id', tag_content='articletags_birds'");
    }
    

    Do the same for the other tags. If you have a very large number (5+), or want users to input their own tags, just do something like:

    foreach ($_POST as $key=>$value)
    {
        if (strpos($key, 'articletags_') === 0) //identity, otherwise false will set this off
        {
             mysql_query("INSERT INTO tags SET id='$article_id', tag_content='$value'");
        }
    }
    

    Note:

    1.) There will be no POST sent if there is no checkbox selected!

    2.) strpos will check if the tag starts with articletags_

    3.) please ESCAPE the the queries! I’ve just shorthanded it all, but malicious PHP can be injected here

    Comment if I’m unclear / if its still not working

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

Sidebar

Related Questions

For example I have a form like this: <form method='post' action='someaction.php' name='myform'> <input type='text'
I have a php file that contains a form (which contains 2 input boxes
I have a simple contact form on a website that has 2 text fields,
Let's assume I have a form with these fields (HTML) <input type=text name=user[name] value=name/>
I have a form that has 3 types of field: (2) text fields that
I have a basic PHP form (a few fields and 2 checkboxes, I want
I have a form in a PHP script and one text field. However when
I have a php form that has a known number of columns (ex. top
I currently have a PHP form that uses AJAX to connect to MySQL and
i have a PHP contact form that submits data, and an email...: <?php $dbh=mysql_connect

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.