Empresas
Empleos
  • Sobre nosotros
  • Soluciones
    • Publicación de vacantes
      Publica tu vacante y recibe candidatos calificados en 48h.
    • Evaluación de candidatos
      500+ pruebas técnicas y psicológicas, más anti-fraude.
    • Headhunting
      Búsqueda ejecutiva a la medida de principio a fin.
    • Nómina + EOR
      Dispersión de nómina y EOR en más de 15 países de LATAM.
  • Precios
  • Empleos

0

199
Vistas
Node & SQL: Check if a value is in the column

I am using Node.js (discord.js specifically) to make a Discord bot. I have a command called !add which takes 2+ arguments. !add Name This is the reply (Name would be args[0]). This is my code I use to check if the Name they input has already been created by a user:

var info = {
 "commandname": args[0],
 "commandreply": args.join(" ").slice(1),
 "username": message.author.name,
 "userid": message.author.id
 }

connection.query("SELECT * FROM commands WHERE commandname = " + args[0], info, function(error) {
  if (error) throw error;

  // should only fireif that command name already exists as a command.
  return message.channel.sendMessage("A command with command name " + args[0] + " already exists."); 
});

// SHOULD fire - as no commands in my database yet. Especially not with that name.
console.log("Trying to insert command " + args[0] + " into Database."); 

But I am getting an error when I run this command:

Error: ER_BAD_FIELD_ERROR: Unknown column 'Name' in 'where clause'

This is my full code for the add command if you want to take a look:https://hastebin.com/qulivabeko.js

This is how my database currently looks: http://imgur.com/a/L7fYI

I am really new to SQL.

over 4 years ago · Santiago Trujillo
1 Respuestas
Responde la pregunta

0

First of all your code is prone to sql injection. First escape all inputs made by the users and then fix your query mistake. It should be like this: SELECT * FROM commands WHERE commandname = '" + args[0] + "'"

over 4 years ago · Santiago Trujillo Denunciar
Responde la pregunta
Encuentra empleos remotos

¡Descubre la nueva forma de encontrar empleo!

Top de empleos
Top categorías de empleo
Empresas
Publicar vacante Precios Comercial
Legal
Términos y condiciones Política de privacidad
© 2026 PeakU Inc. All Rights Reserved.
Andres GPT
Recomiéndame algunas ofertas
Necesito ayuda