0

I have a sqlquery which is: client.query("SELECT * FROM my_table WHERE my_varchar='userInput'").

userInput = req.body.userInput which reads from an inputbox in a jade file.

No matter what I try with different '' or "" around the variables I either get that it generates an error from every input or every input seems correct, although that input does not exist in the table.

Any help would be appreciated!

1 Answer 1

3

The normal answer is don't do that! Inserting raw user input is a great way to get hacked. Do you actually have an input value?

instead:

console.log("User Input is "+ userInput); // or add debug lib and debug("User Input....
client.query("SELECT * FROM my_table WHERE my_varchar = $1", [userInput]);

Also validate your query in psql from a command prompt

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

2 Comments

I tried that, but I still get the same problem, wrong inputs is seen as correct.
Please see revised advice.

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.