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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 31, 20262026-05-31T04:08:53+00:00 2026-05-31T04:08:53+00:00

I think I’ve got a tiny mistake in my code so when I try

  • 0

I think I’ve got a tiny mistake in my code so when I try to add two records to MySQL database it adds them both, but at the moment its only adding the second row that should be inputted. SO for example I have two RefTitle fields, two RefSurname fields and so on!
Some PHP Code:

<?php
if(empty($err)) {
for($i = 0; $i < 2; $i++)
{
$RefTitle = $_POST['RefTitle'][$i];
$RefSurname = $_POST['RefSurname'][$i];
$RefForenames = $_POST['RefForenames'][$i];
$RefInstitute = $_POST['RefInstitute'][$i];
$RefEmail = $_POST['RefEmail'][$i];
$RefTelephone = $_POST['RefTelephone'][$i];
$EmailOK = $_POST['EmailOK'][$i];

$sql_insert = "INSERT into `referees`
(`RefTitle`,`RefSurname`,`RefForenames`,`RefInstitute`, `RefEmail`,    
`RefTelephone`,`EmailOK`)
VALUES

('$RefTitle','$RefSurname','$RefForenames','$RefInstitute','$RefEmail',    
'$RefTelephone','$EmailOK'
)
"; ?>

I have the [] after each name field in my html form.
Thanks

  • 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-31T04:08:55+00:00Added an answer on May 31, 2026 at 4:08 am

    Here’s what I think is happening.

    In the loop, you’re adding the current query to a string, overwriting the previous query. After the loop ends, you run mysql_query but this will only run on the last query generated by the loop.

    You have two ways to fix this:

    1. Execute the query within the loop on every iteration. Pseudo code:

      for ($i = 1 to 100)
      {
      $query = //build your query;

      mysql_query($query);

      }

    2. Alternatively, (and the better way) is to use a value list in your insert statement.

    An insert with a list of values looks like this

    INSERT INTO table VALUES (1,2,3), (4,5,6), (7,8,9)
    

    So, (pseudo code again)

    $query = "INSERT INTO table VALUES ";
    for ($i = 1 to 100)
    {
      $query .= " ("; 
      $query .= "" //comma seperate the values of the current iteration
      $query .= "),";
    }
    

    //after loop ends, remove the trailing extraneous comma

    // execute the entire query at once

    mysql_query($query);
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I think this is specific to IE 6.0 but... In JavaScript I add a
I think I've got it down to the most basic case: int main(int argc,
Think about the games like Spiral Knights and Minecraft(Which I believe both use LWJGL)
Think Windows Explorer's 'Details' view. I need to output my database to this view.
Think of the following code: static int Main() { byte[] data = File.ReadAllBytes(anyfile); SomeMethod(data);
I think it will be very hard for you to read the code but
Think of these lines of code : @boss_locations = BossLocation.order('min_level asc').all @discovered = current_user.discovered_locations.includes(:boss_location).all
Think I have a mysql table TBL of these keys TBL A_KEY X_KEY B_KEY
think user pressed two keys at same time . I want to be notified
I think it's called embossed button.. Is it possible to make one from code?

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.