PostgreSQL pg_query(): Query failed: ERROR: INSERT has more target columns than expressions (PHP)

Ruben Ochoa

I have the following Columns:

CREATE TABLE public.form_filled (
    username character(255) NOT NULL,
    q1 character(255),
    q2 character(255),
    q3 character(255),
    q4 character(255),
    dano character(255),
    q5 character(255),
    q6 character(255),
    q7 character(255),
    q8 character(255),
    q9 character(255),
    q10 character(255),
    q11 character(255),
    q12 character(255),
    q13 character(255),
    q14 character(255),
    q15 character(255),
    q16 character(255),
    q17 character(255),
    q18 character(255),
    q19 character(255),
    q20 character(255),
    q21 character(255),
    q22 character(255),
    q23 character(255),
    q24 character(255),
    q25 character(255),
    q26 character(255),
    q27 character(255),
    q28 character(255),
    q29 character(255),
    registered_date date
);

Date variable:

$date = date('Y-m-d H:i:s');

Query:

INSERT INTO form_filled 
    (
username, q1, q2, q3, q4, dano, q5, q6, q7, q8, q9, q10, q11, q13, q14, q15, q16, q17, q18 ,q19, q20, q21, q22, q23, q24, q25, q26, q27, q28, q29, registered_date
    ) 
    VALUES ('$username', '$q1', '$q2', '$q3', '$q4', '$dano', '$q5', '$q6', '$q7', '$q8', '$q9', '$q10', '$q11', '$q13', '$q14', '$q15', '$q16')
    ,('$q17', '$q18', '$q19', '$q20', '$q21', '$q22', '$q23', '$q24', '$q25', '$q26', '$q27', '$q28', '$q29', '$date')

With My Query I obtain:

Warning: pg_query(): Query failed: ERROR: INSERT has more target columns than expressions LINE 3: ...q5, q6, q7, q8, q9, q10, q11, q13, q14, q15, q16, q17, q18 ,... ^ in C:\xampp\htdocs\Safety\action_form.php on line 61 Error while executing the query: INSERT INTO form_filled ( username, q1, q2, q3, q4, dano, q5, q6, q7, q8, q9, q10, q11, q13, q14, q15, q16, q17, q18 ,q19, q20, q21, q22, q23, q24, q25, q26, q27, q28, q29, registered_date ) VALUES ('username', 'Y', 'N', 'Y', 'Y', 'damaged', 'N', 'N', 'N', 'N', 'N', 'N', 'N', 'Y', 'N', 'N', 'N') ,('Y', 'N', 'N', 'N', 'N', 'N', 'Y', 'Y', 'N', 'Y', 'Y', 'Y', '30', '2021-02-24 16:33:03')

helvete

You are trying to insert into 31 columns, but providing values for 2 records - the first with 17 and the second with 14 records.

Most probably, there is extra ),( halfaway between your values (16 and 17) in the middle.

Try:

INSERT INTO form_filled (
    username, 
    q1, 
    q2, 
    q3, 
    q4, 
    dano, 
    q5, 
    q6, 
    q7, 
    q8, 
    q9, 
    q10, 
    q11, 
    q13, 
    q14, 
    q15, 
    q16, 
    q17, 
    q18,
    q19, 
    q20, 
    q21, 
    q22, 
    q23, 
    q24, 
    q25, 
    q26, 
    q27, 
    q28, 
    q29, 
    registered_date) 
VALUES (
    '$username', 
    '$q1', 
    '$q2', 
    '$q3', 
    '$q4', 
    '$dano', 
    '$q5', 
    '$q6', 
    '$q7', 
    '$q8', 
    '$q9', 
    '$q10', 
    '$q11', 
    '$q13', 
    '$q14', 
    '$q15', 
    '$q16', 
    '$q17', 
    '$q18', 
    '$q19', 
    '$q20', 
    '$q21', 
    '$q22', 
    '$q23', 
    '$q24', 
    '$q25', 
    '$q26', 
    '$q27', 
    '$q28', 
    '$q29', 
    '$date');

Also 12 is missing, but it is perhaps by design.

Collected from the Internet

Please contact [email protected] to delete if infringement.

edited at
0

Comments

0 comments
Login to comment

Related

Postgres error “ERROR: INSERT has more target columns than expressions”

org.postgresql.util.PSQLException: ERROR: INSERT has more expressions than target columns

PostgreSQL ERROR: INSERT has more target columns than expressions, when it doesn't

Python PostgreSQL "error insert has more target columns than expressions" but its not

PostgresSQL - Can't Insert values into table - ERROR: INSERT has more target columns than expressions

INSERT has more target columns than expressions with SELECT in CTE

INSERT a SELECT GROUP BY : more target columns than expressions error

Why I am getting Insert has more target columns than expressions

Warning: pg_query(): Query failed: ERROR: syntax error at or near

php pg_query() not working?

Postgres Warning: pg_query(): Query failed: ERROR: operator does not exist: boolean = integer LINE 1

Having difficulties with pg_query(); in php

PHP & MySQLi Insert Query Failed

Using more than one SELECT in INSERT INTO query

How to insert more than 1000 rows to Postgresql using PHP

PostgreSQL update query with LAG() return "ERROR: more than one row returned by a subquery used as an expression"

Adding more AND expressions to a query?

MySQL/PHP - Need to be able to produce query results with certain columns having more weight than others

Error in using with statement with PostgreSQL insert query

Distribute Query among more than one core (PostgreSQL 9.3)

postgresql display only the query that take more than 2 minute

getting more records than expected with simple query in postgresql

PostgreSQL COPY command - how to write query in more than one line

Query with dynamic target columns

SQL Filter query if column has more than one distinct value

Query who looks if employee has more than 14 vacation days

shop that has served more than 3 people query sql

pivot/unpivot oracle sql query with more than 2 resulting columns

Get sum of more than one table columns with a single query