0

I have found some replies but I don't understand how to get the solution to my problem.

db.js

var mysql = require('mysql');

var connection = mysql.createConnection({
    host: 'localhost',
    user: 'root',
    password: 'dbuser',
    database: 'voley_db'
});

module.exports = connection;

registroRoute.js

var express = require('express');
var router = express.Router();
var db = require('../db');

router.get('/', function(req, res, next) {
    db.query('SELECT * FROM usuarios', function (err, users) {
        if (err) {
            res.send(err);
        } else {
            res.render(
                'registro', {
                users: users
            });
        }
    });
});

router.post('/crearCuenta', function (req, res) {
    var user = {
        nombre: req.body.nombre,
        apelldo: req.body.apellido,
        email: req.body.email,
        password: req.body.password
    };

    db.query("INSERT INTO usuarios SET ?", user, function (err, result) {
        if (err) {
            res.send(err);
        } else {
            res.send(result);
        }
    });
}); 

module.exports = router;

my tabale "usuarios" is:

  • id
  • nombre
  • apellido
  • email
  • password

When I try to create the user, I get:

{"code":"ER_BAD_FIELD_ERROR","errno":1054,"sqlState":"42S22","index":0}

I can't understand why is happening this.

Please help me

1 Answer 1

3

One of your column names is wrong, specifically your object has a key name of "apelldo" but you mentioned that your schema uses "apellido."

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

1 Comment

I can't believe it. Sorry for wasting your time

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.