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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 30, 20262026-05-30T18:11:54+00:00 2026-05-30T18:11:54+00:00

i have an array of company name, i insert each company name as separate

  • 0

i have an array of company name, i insert each company name as separate record.below is the code

<input type="text" name="company_name[]">

$company_name = $_POST['company_name'];

 if($company_name)
 {
    foreach($company_name as $company)
    {
    $mycompany[] = $company;
    }
 }

$val="('".implode("'), ('",$mycompany)."')";
$sql = "INSERT INTO `table`
 (`company_name`) VALUES ".$val."";

The above query look like this and it successfully inserted 2 records in table.

INSERT INTO `table` (`company_name`) VALUES ('DELL'), ('IBM')

Now the problem is that with every company_name there is a company_code which i want to insert with each record and there is 3rd values lets suppose order_num which i also want to insert but the order_num should be same in all records,i need the query below

INSERT INTO `table` (`order_num`,`company_name`,`company_code`) VALUES ('123','DELL','axc89'), ('123','IBM','bxc90')
  • 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-30T18:11:56+00:00Added an answer on May 30, 2026 at 6:11 pm

    Okay, at last you endeavored to produce something understandable

    1) This this code is absolutely useless:

    $company_name = $_POST['company_name'];
    
     if($company_name)
     {
        foreach($company_name as $company)
        {
        $mycompany[] = $company;
        }
     }
    

    as $mycompany being an exact duplicate of $company_name

    2) To get your “very complex” query

    foreach($_POST['company_name'] as $key => $value)
    {
        $name = mysql_real_escape_string($value);
        $code = mysql_real_escape_string($_POST['company_code'][$key]);
        $mycompany[] = "(123,'$name','$code')";
    }
    $sql  = "INSERT INTO `table` (order_num,company_name,company_code) VALUES ";
    $sql .= implode(",",$mycompany);
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

When I have array of objects, when I type the name of variable in
I am using the following code to update a div echo $this->Js->link($station[Company][name], array('action' =>
I Have an array Array ( [0] => Array ( [COMPANY NAME] => 1
Assume we have something like: class Company include Mongoid::Document has_many :users field :name, type:
I have array [Company] => Demo Company 1 [First Name] => Test [Last Name]
I have array of select tag. <select id='uniqueID' name=status> <option value=1>Present</option> <option value=2>Absent</option> </select>
I have an Employee model that has a Name and Company I want to
I have two text blocks, containing company names. Both contain names of hundreds of
firstly I have the following details in my database table field as 'company_name'=>'Test Company'
I have an array of objects, like this: var companies = [ { name

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.