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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 16, 20262026-06-16T12:56:25+00:00 2026-06-16T12:56:25+00:00

I have a form that will send data via POST. I want that data

  • 0

I have a form that will send data via POST. I want that data to go to different MySQL tables based on the POST “name.”

What I have so far is a while loop for the form fields that will name each input in the format: “name”{}$id. I thought that using {} as a delimiter I could then use explode() and use a conditional statement to select which table the data should go to.

Is this the best way to do this? The issue I’m having is also calling the name, since using foreach for example on POST will just return the values and not the names. I have enclosed the code below:

<?php while ($cred = mysql_fetch_array($credentials_process)) { ?>
    <div class="edit-profile-background-inputs">
        <span><input type="text" name="cred{}<?php echo $cred['id']; ?>" value="<?php echo $cred['credentials']; ?>" /></span>
        <span style="margin-left:10px;"><a href="<?php echo "background.php?cred=".$cred['id']; ?>">Remove</a></span>
    </div>
    <?php } ?>

I need those fields named cred{} to go to credentials table, those named edu{} to go to the education table, etc.

  • 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-16T12:56:27+00:00Added an answer on June 16, 2026 at 12:56 pm
    <input type="text" name="cred[<?php echo $cred['id']; ?>]"...
    <input type="text" name="edu[<?php echo $edu['id']; ?>]"...
    

    in PHP

    $insert=array();
    foreach ($_POST['cred'] as $k=>$v)
    {
        $insert[$k]=mysql_real_escape_string($v); // yes I know mysql is being depreciated
    }
    
     $sql='INSERT INTO cred ('. implode(',', array_keys($insert)).') VALUES ('. implode(',', $insert).');
    

    repeat for $_POST['edu']

    If your results set is such that you’re outputting more than one row with the same key

    $i=0;
    while ($cred = mysql_fetch_array($credentials_process)) { ?>
        <input type="text" name="cred[$i][<?php echo $cred['id']; ?>]"...
        ...
        $i++;
    }
    

    If you print_r($_POST) from that you’ll be able to figure out how to deal with them.

    NB. For safety I would also make sure only the expected posted vars get used

    $allowed=array('cred_id', 'cred_something', 'etc');
    
    foreach ($_POST['cred'] as $k=>$v){
        if (!in_array($k, $allowed)) continue;
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

(Using MySQL and PHP) I have a search form that will allow my users
I have a form that send information to a mysql db. Error messages and
I have a html form that sends POST data to php file. In php
The functionality I'm looking for: I have a form that will search my 'Proposal'
I have a windows form that has two DataGridViews (DGVs) that will hold 25,000+
I have a form in my application that will fill using Unicode characters (Non
I have created a form with knockout that will allow the ability to give
I have a form with a hidden Came from Adwords field that will be
I currently have a simple form that when you click the save button will
Javascript I have code that will hide various sections in a MS CRM form

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.