Going nuts with this error

Hi all,

I need a little help trying to understand what am i doing wrong. I’m doing a web app for my programming class at the University and this error is not letting me advance.
The project consists in a web app that the user inserts some data and saves it into MySQL database.

The error that Node is showing is the following:

App listen in port 3000
{ primeiro: 'Ricardo',
  ultimo: 'Nunes',
  email: 'someemail@gmail.com',
  pais: 'Portugal',
  cidade: 'Almada',
  morada: 'Almada' }
ReferenceError: utilizadores is not defined

The table (utilizadores) exists but Express say’s otherwise. Here’s the index.js file:

var express = require('express');
var app = express();
var bodyParser = require('body-parser');


app.listen(3000, function(){
    console.log('App listen in port 3000');

var mysql = require('mysql');

var connection = mysql.createConnection({
    host: 'localhost',
    port: '3307',
    user: 'root',
    password: 'password',
    database: 'rco'

    if(err) throw err

app.get('/', function(req,res,next){

app.post('/myaction', function(req, res){
    res.write('You sent the first name "' + req.body.primeiro+'".\n');
    res.write('You sent the last name "' + req.body.ultimo+'".\n');
    res.write('You sent the email "' + req.body.email+'".\n');
    res.write('You sent the pais "' + req.body.pais+'".\n');
    res.write('You sent the cidade "' + req.body.cidade+'".\n');
    res.write('You sent the morada "' + req.body.morada+'".\n');
    //res.write('You sent the familia "' + req.body.familia+'".\n');

    connection.query("insert into "+utilizadores+" (PrimeiroNome, UltimoNome,Email, Pais,Cidade,Morada) values ('"+req.body.primeiro+"','"+req.body.ultimo+"','"+req.body.email+"','"+req.body.pais+"','"+req.body.cidade+"','"+req.body.morada+"')",function(err, result){
            throw err;

Thanks in advance. This error is getting on my nerves…a simple select to the database retrieves the same error…

I cleaned up your code.
You need to use triple backticks to post code to the forum.
See this post for details.

Where is utilizadores defined?
If it’s not then you can either define it in a var or just remove the “+ and +” between it.

I don’t think the error is coming from the database, but from Node. Unless you want to define a constant somewhere

const UTILIZADORES = "utilizadores";

then you need to include the string literal with the rest of the string query

onnection.query("insert into utilizadores  (PrimeiroNome, UltimoNome,Email, Pais,Cidade,Morada) /* ... */ ")

Sorry about the late reply guys. It worked, i’ve checked the insert code again, by the recommendation of PortableStick, and it worked.

I had the +utilizadores+ but forgot to set the variable utilizadores. Remove the plus signs and voila.

I can’t believe the time that i been with this error and it was a very simple mistake that i did…

Thanks again guys :slight_smile: