0

Am curretly facing the following error when i try to query using express

  code: 'ER_OPERAND_COLUMNS',
  errno: 1241,
  sqlMessage: 'Operand should contain 1 column(s)',
  sqlState: '21000',
  index: 0,
  sql: "insert into quiz(user_pk,question,answer,choices,discussion) values (1, 'what is math', 'study of calculations', ('study of calculations', 'study of computing', 'study of books'), 'its amaizing')"
}

routes

.post((req, res) => {
        query =
            "insert into quiz(user_pk,question,answer,choices,discussion) values ?";
        values = [Object.values(req.body)];
        console.log(values)
        connection.query(
            query,
            [values],
            (err, result) => {
                if (err) throw err;
                res.json({ message: "question sussefully created" });
            }
        );
    });

data i want to insert

{
    "user_pk":1,
    "question":"what is math",
    "answer":"study of calculations",
    "choices":["study of calculations","study of computing","study of books"],
    "discussion":"its amaizing"
}

example of query i want to perform

insert into quiz(user_pk,question,answer,choices,discussion)
values(1,'what is physics?','study of matter','["study of matter","study of dances","study of matter"]','lorem ipsum dolor lorem');

here is the quiz table

CREATE TABLE if NOT EXISTS quiz(
    quiz_pk INT NOT NULL AUTO_INCREMENT,
    user_pk INT NOT NULL,
    question VARCHAR(255) NOT NULL,
    answer VARCHAR(255) NOT NULL,
    choices JSON NOT NULL,
    discussion VARCHAR(255) NOT NULL, 
    PRIMARY KEY (quiz_pk),
    FOREIGN KEY (user_pk) REFERENCES user(user_pk)
);

please help me out.Thanks alot

4

0

Browse other questions tagged or ask your own question.