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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 24, 20262026-05-24T23:40:53+00:00 2026-05-24T23:40:53+00:00

i want to insert some data into a data table, for a wordpress plugin.

  • 0

i want to insert some data into a data table, for a wordpress plugin.
the data is taken with POST.
i have multiple results (taken with post), but $wpdb->insert only inserts me the last result (practically overwrites the data). why is that?

here is my code:

html:

echo '<label for="reduceri-post-category"><b>' . __("What categories should be the adverts", 'appplugin' ) . '</b></label><br /><br /><br />';
    ?>

    <?php foreach ($the_data[categories]  as $sat): ?>
    <b> <?= $sat[name]; ?> <br /> </b>
            <?php foreach ($sat[subcategories] as  $cat):
    ?>

    &nbsp; &nbsp; &nbsp;<input type="checkbox" name="reduceri-post-category" value="<?= $cat[sid] ?>" /> <?php echo $cat[name]; echo $cat[sid]; ?><br />

    <? endforeach; ?>
    <? endforeach; ?>




global $wpdb;


    $thedata['reduceri-post-category'] = $_POST['reduceri-post-category'];


    $table_name = $wpdb->prefix . "reduceri";


    foreach ($thedata as $key => $value) { 
    if( $post->post_type == 'revision' ) return;
    if ( $post->post_type == 'post'){

        $wpdb->insert($table_name, array( 'time' => current_time('mysql'), 'post' => $post->ID, 'category' => $value));
    }
    }

what can i do in order to be able to insert ALL the results, not only the last one?? thanks a lot!

  • 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-05-24T23:40:54+00:00Added an answer on May 24, 2026 at 11:40 pm

    What is in reduceri-post-category?

    You say that you have multiple values in post. How are these multiple values passed into your plugin? Does reduceri-post-category contain multiple values? Do you use separate keys for each of the values? For example, reduceri-post-category2/3/4?

    You are using a foreach to iterate through $thedata. However I don’t see anywhere in your code where you actually create an array in $thedata. So your foreach is only ever going to execute once, and it will execute based on what is inside $_POST['reduceri-post-category'];

    What I think you want to do, tough to say, is one of these two scenarios.

    Scenario 1 – multiple post keys hold data you are after

    $thedata[foo1] = $_POST[foo1];
    $thedata[foo2] = $_POST[foo2];
    $thedata[foo3] = $_POST[foo3];
    foreach ($thedata as $key => $value) { }
    

    Or (pseudeocode) – a single post key holds all your category data. So you have to split it up and then execute on each one.

    $thedata = explode("?", $_POST[reduceri-post-category]);
    foreach ($thedata as $key => $value) { }    
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I want to insert some data into a table and I want the multiple
I want to insert some data into a table (id PK autoincrement, val) with
I have some data in a view which I want to insert into a
So, I want to insert some data into a MySQL table where the table
I want to insert some data into a table associated with dates for the
I want to do some quick inserts but avoid duplicates into a Table. For
I need to create an SQL query to insert some data into a table
I have a stored procedure that first inserts some data into a temp table
I want to insert some simple data the query is: INSERT INTO categories_lang (category_id,language_id,name,description,alias)
I am having a scenario where I have to insert some master data into

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.