Business
Jobs
  • About Us
  • Solutions
    • Job Postings
      Post your job and receive qualified candidates in 48h.
    • Candidate Assessments
      500+ technical and psychological tests, plus anti-fraud.
    • Headhunting
      Tailor-made executive search from start to finish.
    • Payroll + EOR
      Payroll dispersal and EOR across 15+ LATAM countries.
  • Pricing
  • Jobs

0

186
Views
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 answers
Answer question

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 Report
Answer question
Find remote jobs

Discover the new way to find a job!

Top jobs
Top job categories
Business
Post vacancy Pricing Sales
Legal
Terms and conditions Privacy policy
© 2026 PeakU Inc. All Rights Reserved.
Andres GPT
Show me some job opportunities
There's an error!