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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 17, 20262026-06-17T14:22:27+00:00 2026-06-17T14:22:27+00:00

I am attempting to run the following query which is a multi insert. Everything

  • 0

I am attempting to run the following query which is a multi insert. Everything seems fine but it throws this error:

SQLSTATE[21000]: Cardinality violation: 1241 Operand should contain 1 column(s)

My code is as follows

$report_categories=array(1,2,3);
$report_categories=array_unique($report_categories);    
$rowPlaces = '(' . implode(', ', array_fill(0, 2, '?')) . ')';
$allPlaces = implode(', ', array_fill(0, count($report_categories), $rowPlaces));

$add_report_types=$this->prepare("
    INSERT INTO report_types (
        report_id,
        category
    ) VALUES (
        " . $allPlaces . "
    )");

$i=1;
foreach($report_categories as $category_id){
    $add_report_types->bindValue($i, $report_id, PDO::PARAM_INT);
    $i++;
    $add_report_types->bindValue($i, $category_id, PDO::PARAM_INT);
    $i++;
}
$add_report_types->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-06-17T14:22:28+00:00Added an answer on June 17, 2026 at 2:22 pm

    You might want to try it without the parentheses in the values part of your query:

    $add_report_types=$this->prepare("
        INSERT INTO report_types (
            report_id,
            category
        ) VALUES " . $allPlaces);
    

    If I understand it right, $allPlaces should contain a string that looks like this:

    (?, ?), (?, ?), (?, ?)
    

    So you want your query to look like:

    INSERT INTO report_types (
        report_id,
        category
    ) VALUES (?, ?), (?, ?), (?, ?);
    

    http://dev.mysql.com/doc/refman/5.5/en/insert.html

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

Sidebar

Related Questions

I am attempting to run a sql query but get the following error: Incorrect
I get an error (1064) when attempting to run the following... (MySql 5.5.9) query:
while attempting to run rake, I run into the following error: heroku rake db:migrate
I am getting the following error message when compiling or attempting to run my
I'm using gvim and rails.vim and getting the following error when attempting to run
I am attempting to run the following query sqlcmd -STEMP7 -E -devolive_base -w256 -QEXIT(DECLARE
After attempting to run a migration in Laravel 4 I received the following error:
I'm getting the following error when attempting to run my build script. /var/lib/jenkins/jobs/IPS (trunk)/workspace/build.xml:62:
I am attempting to run the following query: (IF(book.book_type_id = 1, IF(inventory.cost < (follette_title.usedbuyingprice
I'm attempting to run mongrel_rails, but I get the following: the program can't start

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.