I'm using mysql with nodeJS and creating a query. The rows I get for the query are 'undefined'. This has never happened to me before, and I'm stumped.
// check if URL already exists in database connection.query("SELECT * FROM shorturl WHERE urlsource='?'", [url], function(error, rows, fields){ if (error) { console.log(error); } if (rows.length == 0) { console.log(rows); //prints 'undefined' insertURL(); } else { console.log("creating new entry"); printURL(); } });
console.log(rows);that printsundefined? This does not make sense, because then therows.lengthwould throw a cannot read property length of undefined error.console.log(error);does not log an error. You should wrap all of the code belowif (error) { console.log(error); }in theelseblock of theif (error).... WHERE urlsource = '?').