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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 8, 20262026-06-08T01:34:03+00:00 2026-06-08T01:34:03+00:00

I am allowing user to create up to ten categories using text boxes in

  • 0

I am allowing user to create up to ten categories using text boxes in a form. To do this I have ten textboxes in the form with name = cat[]. The first time they enter categories–however many, up to ten, on the receiving end, I just collect the array of categories and save them to a table of categories using an insert statement. So far so good.

However, now I want to let them change categories they already set or add extras up to ten total. The categories they already set have ids. So I echo the ids to the form along with the category names. My problem is how do I collect the names and ids now? New ones need to be inserted and existing ones may need to be updated in the table? For some reason, I’m at a total loss how to do this. This is what I have so far>

Table Cats

id | catname | userid

Form page:

//retrieve existing cats if any...also get catids

echo '<form action = storecats.php method=post>';
$i=1;
//Get all existing cats
while($row = mysql_fetch_array($res))
{
    $catname = $row['catname'];
    $catid = $row['id'];
    echo '<input type = "text name="cat[]" value="'.$catname.'">Cat 1';
    echo '<input type="hidden" name="id[]" value = "'.$catid.'">';
    $i = $i+1;
}
//empty boxes up to ten.
while($i <= 10){
    echo '<input type="text" size=18 name="cat[]" value=""> Cat '.$i.'<br>';
    $i = $i+1;
}//end appending of blank categories
echo '<input type="submit" name="submit" value="submit"></form>';

On receiving end, I can collect the array for cat and id.

$idarray = $_POST['id']; //there will be as many elements as there were ids
$catarray = $_POST['cat'];  //there will be ten elements in array

Where there is an id, I want to perform an update whereas where there is no id I want to insert unless the value is blank.

My problem is I can’t figure out how to link the id and the cat names being received in the different arrays. Note, there will always be ten cat names but there will only be as many ids as were in the table for that user previously.

  • 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-08T01:34:04+00:00Added an answer on June 8, 2026 at 1:34 am

    You can do it with 2 array on HTML side:

        $x=0;
        while ($row = mysql_fetch_array($res))
        {
            echo '<input type="text" name="updateCat['.$row["id"].']" value="'.$row["catname"].'"> Cat Name';
            $x++;
        }
    
        // new ones
        for(;$x<10;$x++)
        {
            echo '<input type="text" name="newCat[]">';
        }
    

    and on php side:

        // update old categories
        foreach ($_POST["updateCat"] as $key => $value)
        {
            mysql_update ("UPDATE table SET name = $value WHERE id = $key");
        }
    
        // insert 
        foreach ($_POST["newCat"] as $value)
        {
            mysql_update ("INSERT INTO table {...}");
        }
    

    You have also check that there are not more than 10 Categories when inserting new ones.

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

Sidebar

Related Questions

I have a form allowing a user to signup for a news letter which
I have an input form with two textareas allowing a user to type in
How do I create a form in drupal with about 5 text fields, allowing
I have a form that needs to be dynamic, allowing the user to add
I have a web application that functions as a dashboard, allowing a user to
I am generating user control according to search result. And allowing to change text
As you can see here , I'm allowing a user to dynamically create a
I'm using storyboard to create a grouped UITableView . Within the table I have
I'm creating a basic concurrent server allowing a user to download a file using
I'm using a SqlDataSource in a very simple application. I'm allowing the user to

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.