Empresas
Empregos
  • Sobre nós
  • Soluções
    • Publicação de vagas
      Publique sua vaga e receba candidatos qualificados em 48h.
    • Avaliações de candidatos
      Mais de 500 testes técnicos e psicológicos, mais anti-fraude.
    • Headhunting
      Busca executiva personalizada do início ao fim.
    • Folha de Pagamento + EOR
      Dispersão de folha e EOR em mais de 15 países da LATAM.
  • Preços
  • Empregos

0

188
Visualizações
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 Respostas
Responde à pergunta

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 Relatório
Responde à pergunta
Encontrar trabalhos remotos

Descubra a nova forma de encontrar um emprego!

melhores empregos
Principais categorias de trabalho
Empresas
Postar vaga Preços Comercial
Jurídico
Termos e Condições Política de privacidade
© 2026 PeakU Inc. All Rights Reserved.
Andres GPT
Recomende algumas ofertas para mim
Preciso de ajuda