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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 13, 20262026-06-13T08:55:27+00:00 2026-06-13T08:55:27+00:00

I am attempting to UPDATE records within my MySQL database. I build the prepared

  • 0

I am attempting to UPDATE records within my MySQL database.

I build the prepared statement using arrays / loops:

$sql =  "UPDATE table01 SET ";  
        foreach($values as $value)
        {
        $sql .="$value = :$value, ";
        }
        $sql = rtrim($sql,', ');    
        $sql .=" WHERE id = '$id'";

then I prepare this statement:

try 
{
$pdo = new PDO('mysql:host=localhost; dbname=db01', $username, $password);
$pdo->setAttribute(PDO::ATTR_ERRMODE, PDO::ERRMODE_EXCEPTION);

$stmt = $pdo->prepare($sql);

Then I bind each of the tokens / placeholders in the prepared statement to the values to be inserted using another loop:

foreach(array_combine($values, $variables) as $value=>$variable)
{
$stmt->bindParam(':$value', $variable);
}

$stmt->execute();         

where $values is an array of column headers in the database (therefore ‘:$value’ is a set of token names corresponding to them) and $variables is an array of variables containing data to be stored.

When I run this, I am given the error:

Error: SQLSTATE[HY093]: Invalid parameter number: number of bound variables does not match number of tokens

But as you can see I’m forming them from arrays – I’ve done counts on the arrays to ensure the elements match 1:1 and they do:

FYI:

$count1 = count($values);
$count2 = count($variables);

echo $count1;
echo $count2;

gives:
7575

(they both have 75 elements in them)

  • 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-13T08:55:28+00:00Added an answer on June 13, 2026 at 8:55 am

    Single quotes don’t interpolate variables.

    $stmt->bindParam(':$value', $variable);
    

    should be

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

Sidebar

Related Questions

I'm currently attempting to update existing records within a MySQL database. Prior to the
I am attempting to insert many records using T-SQL's MERGE statement, but my query
I'm attempting to construct an SQL statement for MySQL that will update a single
i am attempting to update approximately 150,000 records in a table in SQL 2005
I currently have a problem attepting to update a record within my database. I
I am using Subsonic v3.0.0.3 with the Linq templates. I am attempting to update
When attempting to update value, these error are occuring, 02-09 11:37:53.573: ERROR/AndroidRuntime(4809): android.database.sqlite.SQLiteException: attempt
I'm attempting to update my database table with the following code: public void onUpgrade(SQLiteDatabase
Using LINQ-to-SQL, I would like to automatically create child records when inserting the parent
I'm attempting to both display a list from data in an external MySQL database

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.