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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 24, 20262026-05-24T01:08:04+00:00 2026-05-24T01:08:04+00:00

When I run the following code: // Loop through each store and update shopping

  • 0

When I run the following code:

  // Loop through each store and update shopping mall ID

  protected function associateShmallToStore($stores, $shmall_id) {

    foreach($stores as $store_id) {
      $sql .= 'UPDATE my_table SET fk_shmallID = :shmall_id WHERE id = :store_id';
      $stmt = $this->db->prepare($sql);
      $stmt->bindParam(':shmall_id', $shmall_id);
      $stmt->bindParam(':store_id', $store_id);
      $stmt->execute();
    }

  } 

I get the following message:
Warning: PDOStatement::execute() [pdostatement.execute]: SQLSTATE[HY093]: Invalid parameter number: mixed named and positional parameters

I’ve also tried the following without success (without $stmt->bindParam):
$stmt->execute( array($shmall_id, $store_id));

I don’t understand what I’m doing wrong.

UPDATE
I’ve updated my code to reflect what I actually got in my source code. There should not be any typos here.

UPDATE 2
I tried this, but I still get the same error message.

  protected function associateShmallToStore($stores, $shmall_id) {
    $i = 0;

    $sql .= "UPDATE sl_store ";

    foreach($stores as $store_id) {
      $i++;
      $sql .= 'SET fk_shmallID = :shmall_id, lastUpdated = NOW() WHERE id = :store_id_'.$i.',';  
    }

    $sql = removeLastChar($sql);
    $stmt = $this->db->prepare($sql);

    $stmt->bindParam(':shmall_id_'.$i, $shmall_id);

    $i = 0;
    foreach($stores as $store_id) {
      $i++;    
      $stmt->bindParam(':store_id_'.$i, $store_id);
    }

    $stmt->execute();
  }

This is the output of the SQL query:

UPDATE sl_store 
  SET fk_shmallID = :shmall_id, lastUpdated = NOW() WHERE id = :store_id_1,
  SET fk_shmallID = :shmall_id, lastUpdated = NOW() WHERE id = :store_id_2

UPDATE 3
The code I endet up using was this:

    foreach($stores as $store_id) {
      $sql = "UPDATE sl_store SET fk_shmallID = :shmall_id WHERE id = :store_id";
      $stmt = $this->db->prepare($sql);
      $stmt->bindParam(':shmall_id', $shmall_id);
      $stmt->bindParam(':store_id', $store_id);
      $res = $stmt->execute();
    } 
  • 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-24T01:08:06+00:00Added an answer on May 24, 2026 at 1:08 am

    It’s just as the error says, you have mixed named and positional parameters:

    • :name (named)
    • :person_id (named)
    • ? (positional)

    More than that, you have the named parameter :person_id, but you’re binding to :id.

    These are your parameters, I’ll call them P1, P2 and P3:

    UPDATE my_table SET name = :name WHERE id = :person_id ?
                               ^ P1             ^ P2       ^ P3
    

    And this is where you bind them:

      $stmt->bindParam(':name', $name); // bound to P1 (:name)
      $stmt->bindParam(':id', $person_id); // bound to nothing (no such param :id)
    

    You probably want to bind the second parameter to :person_id, not to :id, and remove the last positional parameter (the question mark at the end of the query).

    Also, each iteration through the foreach loop appends more to the query, because you’re using the concatenation operator instead of the assignment operator:

    $sql .= 'UPDATE my_table SET name = :name WHERE id = :person_id ?';
    

    You probably want to remove that . before =.

    For more about this, take a look at the Prepared statements and stored procedures page in the PDO manual. You will find out how to bind parameters and what the difference is between named and positional parameters.

    So, to sum it up:

    1. Replace the SQL line with:

      $sql = 'UPDATE my_table SET name = :name WHERE id = :person_id';
      
    2. Replace the second bindParam() call with:

      $stmt->bindParam(':person_id', $person_id);
      
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I usually loop through lines in a file using the following code: open my
I'd like some help with the following jQuery code if possible... $(document).ready(function() { $('table.sortable').each(function()
When I run the following code to test copying a directory, I get a
I want to run the following code: ajaxUpdate(10); With a delay of 1 second
When I run the following code: private void button1_Click(object sender, EventArgs e) { Bitmap
When I run the following code, I get the exception below: ''# NOTE: ExcelApp
When I run the following code, it only seems to be downloading the first
When I try to run the following code (from the REPL) in Clojure: (dotimes
I am trying to run the following code from within Eclipse: Process process =
Why whenever I compile and run the following code in Visual Studio 2008: double

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.