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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 15, 20262026-06-15T03:30:22+00:00 2026-06-15T03:30:22+00:00

im trying to update multiple records in my table so im wondering if there´s

  • 0

im trying to update multiple records in my table so im wondering if there´s something wrong in this script as im only getting updated the last record.. this is the complete code http://pastie.org/5453954

 for ($i = 0; $i < count($_POST['id_servtype']); $i++){

    $servtype = $_POST['id_servtype'][$i];    
    $project = $_POST['id_project'][$i];
    $quantity = $_POST['tableQuantity'][$i];
    $pus = $_POST['tablePus'][$i];
    $puc = $_POST['tablePuc'][$i];
    $totalitem = $_POST['tableTotal'][$i];

    $sql = "update sales_order_items
    set
    id_project=?,
    id_service_type=?,
quantity=?,
    unit_price_no_tax=?,
    unit_price=?,
    total_item_imp=?
    where
    id_so=?
    and
    id_soitems=?
    ";

    $stmt = $this->dbh->prepare($sql);
    $stmt->bindValue(1, $project, PDO::PARAM_INT);
    $stmt->bindValue(2, $servtype, PDO::PARAM_INT);
    $stmt->bindValue(3, $quantity, PDO::PARAM_STR);
    $stmt->bindValue(4, $pus, PDO::PARAM_STR);
    $stmt->bindValue(5, $puc, PDO::PARAM_STR);
    $stmt->bindValue(6, $totalitem, PDO::PARAM_STR);
    $stmt->bindValue(7, $_POST["id"], PDO::PARAM_STR);
    $stmt->bindValue(8, $_POST["iditem"], PDO::PARAM_STR);
    $stmt->execute();

    }

    echo("Correct edition");
  • 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-15T03:30:23+00:00Added an answer on June 15, 2026 at 3:30 am

    There is something wrong with your logic: the values used in your WHERE clause are always the same, so you’re always updating all records, each time using new values.
    Logically, when your script has finished, only the last update will be visible, all previous updates have been overwritten. A simple example:

    $newVals = array(1,2,3);
    while($val = array_shift($newVals))
    {
        $query = 'UPDATE myDB.tbl SET someField = :val WHERE id = 1';
        $stmt = $pdo->prepare($query);
        $stmt->execute(array('val' => $val));
    }
    

    Is the same as writing:

    UPDATE myDB.tbl SET someField = 1 WHERE id = 1;
    UPDATE myDB.tbl SET someField = 2 WHERE id = 1;
    UPDATE myDB.tbl SET someField = 3 WHERE id = 1;
    

    So the record(s) with id 1 are updated a total of three times, each time undoing the last update

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

Sidebar

Related Questions

I am trying to update multiple records in the table using the temporary table
This is the code giving me issue - I'm trying to update multiple records
I'm trying to update multiple rows in one table in MySQL database by doing
I'm trying to update all records in one table with the values found in
I have a table student_log , and there are multiple records for a single
I am basically just trying to update multiple values in my table. What would
I'm trying to update one field of multiple records in a model, Lead. Each
I'm trying to use saveAll correctly to update User records for multiple relational models.
I have the following SQL statement where i'm trying to update multiple rows matching
I am trying update text views while this loop is processing. Here is my

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.