So I'm developing an API for mySQL with nodejs. Trying to make a function that inserts into two different tables.

```
INSERT INTO account_details (username, first_name, last_name, gender, mobile_number, postal_code, email, activated) VALUES (?, ?, ?, ?, ?, ?, ?, ?)

```

and

```
INSERT INTO passwords (username, password) VALUES (?, ?)

```

What's the proper way to do it?

Right now I have this, which works perfectly except it crashes my nodejs server, giving the error below.

```
    addUser(request, respond) {
        var userObject = new User(request.body.username, request.body.password, request.body.first_name, request.body.last_name, request.body.gender, request.body.mobile_number, request.body.postal_code, request.body.email, request.body.activated, null, null);
        var sql = "INSERT INTO account_details (username, first_name, last_name, gender, mobile_number, postal_code, email, activated) " +
                    "VALUES (?, ?, ?, ?, ?, ?, ?, ?)";
        var password = "INSERT INTO passwords (username, password) VALUES (?, ?)";

        var values = [userObject.getUsername(), userObject.getFirstName(), userObject.getLastName(), userObject.getGender(),
                    userObject.getMobileNumber(), userObject.getPostalCode(), userObject.getEmail(), userObject.getActivated()];

        var passvalues = [userObject.getUsername(), userObject.getPassword()];

        db.query(sql, values, function (error, result) {
            if (error) {
                throw error;
            }
            else {
                respond.json(result);
            }
        });
        db.query(password, passvalues, function (error, result) {
            if (error) {
                throw error;
            }
            else {
                respond.json(result);
            }
        });
    }

```

```
Error: Can't set headers after they are sent.

```

Can anyone help with the proper syntax? Thanks in advance.