2

I've been working with mysql in nodejs for a bit and I can't seem to figure out how to use the query with multiple where statements. Like:

SELECT * FROM user_information WHERE a=a or b=b

Right now i have this as my code:

    connection.query("SELECT * FROM user_information WHERE username=" + registerarray[1] + " OR email=" + registerarray[3],function(err, results){
            if (err){console.error(err);}
    });

Thank you and best regards

Me

1 Answer 1

1

results is rows of response from mysql.

Let's simplify parts:

const 
  q = "SELECT * FROM user_information WHERE username=? OR email=?", // You can use placeholders like ? marks 
  args = [registerarray[1], registerarray[3]]; // array of values that will be set to placeholders (will be escaped for security)
connection
  .query(
    q, // our query
    args,  // placeholder values
    (err, records) => { // query response scope begins here
      if (err) {
        console.error(err);
      }

      console.log('THIS IS RESULT OF QUERY EXECUTION:');
      console.log(records); // this is result, already fetched array
    });
Sign up to request clarification or add additional context in comments.

Comments

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.