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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 18, 20262026-06-18T05:51:29+00:00 2026-06-18T05:51:29+00:00

foreach(($no_items as $key=>$txt ) && ($b_cost as $key=>$txt1 )) { $sql1 = INSERT INTO

  • 0
    foreach(($no_items as $key=>$txt ) && ($b_cost as $key=>$txt1 ))
    {
    $sql1 = "INSERT INTO bulk_s (`no_items`,`b_cost`) VALUES ('$txt[$key]','$txt1[$key]')       ";
    }

I have two dynamically created arrays in my php page whose values I need to store in the DB in the same row

my js code

    function changeIt()
    {
    my_div.innerHTML = my_div.innerHTML +"<br> items <input type='text'  name='txt[]'+ i>"

    my_div.innerHTML = my_div.innerHTML +" cost <input type='text'  name='txt1[]'+ j>"
    i++;
    j++;
    } 
  • 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-18T05:51:31+00:00Added an answer on June 18, 2026 at 5:51 am

    Your foreach syntax isn’t valid PHP. If you want to iterate over two arrays with identical keys at the same time, you have to iterate over the keys instead:

    foreach (array_keys($no_items) as $key) {
        $txt = $no_items[$key];
        $txt1 = $b_cost[$key];
        $sql1 = "INSERT INTO bulk_s …";
    }
    

    However, note that you should never construct SQL statements like this, it makes them liable to SQL injections. This is an inacceptable coding practice. In the best case it makes your program less elegant, in the worst case it opens you up to lawsuit, and there is a very simple superior solution.

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

Sidebar

Related Questions

I have lists of about 20,000 items that I want to insert into a
I have a dictionary where entry values can reference another entry by key eventually
foreach ($topicarray as $key=>$value){ $files = mysql_query(mysqlquery); while($file = mysql_fetch_array($files)){ extract($file); $topicarray[$value] = array(
I have tried both these methods to remove the 0 values from this array
I have a code first model: namespace InternetComicsDatabase.Models { public class Issue { [Key]
I have the following two functions which take two dictionaries and recursively add their
I can't have the same key. But a simple (and effective) solution is put
I have a database that has two tables, one of which contains a foreign
I have a class that gets arranged into a hierarchy, such as this: class
<?php $url = 'https://www.googleapis.com/shopping/search/v1/public/products?key=thekey&country=US&q=nintendo+wii'; $data = curl_init($url); curl_setopt($data, CURLOPT_RETURNTRANSFER, TRUE); curl_setopt($data, CURLOPT_HEADER, 0); $product_result

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.