2

I am getting the following error when trying to insert multiple inserts based on one form

"sql: "INSERT INTO ( pokemon (pokemonname) VALUES ('sadfasd'), INSERT INTO location (locationname) VALUES ('asdfasdf'), INSERT INTO primarymove (primarymovename) VALUES ('asdf'), INSERT INTO type (typename) VALUES ('2'))"

sqlMessage: "You have an error in your SQL syntax; check the manual that corresponds to your MariaDB server version for the right syntax to use near '( pokemon (pokemonname) VALUES ('sadfasd'), INSERT INTO location (locationname) ' at line 1","

And below is my post request

   router.post('/', function(req, res){
    var mysql = req.app.get('mysql');
    var sql = "INSERT INTO pokemon (pokemonname) VALUES (?), INSERT INTO location (locationname) VALUES (?), INSERT INTO primarymove (primarymovename) VALUES (?), INSERT INTO type (typename) VALUES (?)";
    var inserts = [req.body.pokemonname, req.body.locationname, req.body.primarymovename, req.body.typename];
    sql = mysql.pool.query(sql, inserts, function(error, results, fields){
            if(error){
                    res.write(JSON.stringify(error));
                    res.end();
            } else{
                    res.redirect('/pokemon');
             }
    });

});

I am going to assume it has to do with my multiple INSERT INTO requests, I am basically trying to do multiple insert statements going to various different tables. Or is it not possible?

1
  • 1
    The comma is not used to separate statements Commented Nov 19, 2017 at 0:24

1 Answer 1

1

You need to replace commas with ';'

Sign up to request clarification or add additional context in comments.

1 Comment

Thank you - I updated with ; but still getting the error

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.