MySQL Forums
Forum List  »  Connector/Node.js

Error: ER_EMPTY_QUERY: Query was empty
Posted by: Thijmen De Groote
Date: December 24, 2022 06:24AM

I'm working on a log in form with node.js and mysql as the database. When I run the programm and try to register a new user I get this error when I press submit.

When I press submit I get the folowing error in the console in the inspect page in chrome: error and I get in the terminal inside vs code the following error:

node:internal/process/promises:288
triggerUncaughtException(err, true /* fromPromise */);
^

Error: ER_EMPTY_QUERY: Query was empty
at Sequence._packetToError (D:\programmeer stuff\javascript\informatica site\New folder\node_modules\mysql\lib\protocol\sequences\Sequence.js:47:14)
at Query.ErrorPacket (D:\programmeer stuff\javascript\informatica site\New folder\node_modules\mysql\lib\protocol\sequences\Query.js:79:18)
at Protocol._parsePacket (D:\programmeer stuff\javascript\informatica site\New folder\node_modules\mysql\lib\protocol\Protocol.js:291:23)
at Parser._parsePacket (D:\programmeer stuff\javascript\informatica site\New folder\node_modules\mysql\lib\protocol\Parser.js:433:10)
at Parser.write (D:\programmeer stuff\javascript\informatica site\New folder\node_modules\mysql\lib\protocol\Parser.js:43:10)
at Protocol.write (D:\programmeer stuff\javascript\informatica site\New folder\node_modules\mysql\lib\protocol\Protocol.js:38:16)
at Socket.<anonymous> (D:\programmeer stuff\javascript\informatica site\New folder\node_modules\mysql\lib\Connection.js:88:28)
at Socket.<anonymous> (D:\programmeer stuff\javascript\informatica site\New folder\node_modules\mysql\lib\Connection.js:526:10)
at Socket.emit (node:events:513:28)
at addChunk (node:internal/streams/readable:324:12)
--------------------
at Protocol._enqueue (D:\programmeer stuff\javascript\informatica site\New folder\node_modules\mysql\lib\protocol\Protocol.js:144:48)
at Connection.query (D:\programmeer stuff\javascript\informatica site\New folder\node_modules\mysql\lib\Connection.js:198:25)
at register (D:\programmeer stuff\javascript\informatica site\New folder\controllers\register.js:9:12)
at Layer.handle [as handle_request] (D:\programmeer stuff\javascript\informatica site\New folder\node_modules\express\lib\router\layer.js:95:5)
at next (D:\programmeer stuff\javascript\informatica site\New folder\node_modules\express\lib\router\route.js:144:13)
at Route.dispatch (D:\programmeer stuff\javascript\informatica site\New folder\node_modules\express\lib\router\route.js:114:3)
at Layer.handle [as handle_request] (D:\programmeer stuff\javascript\informatica site\New folder\node_modules\express\lib\router\layer.js:95:5)
at D:\programmeer stuff\javascript\informatica site\New folder\node_modules\express\lib\router\index.js:284:15
at Function.process_params (D:\programmeer stuff\javascript\informatica site\New folder\node_modules\express\lib\router\index.js:346:12)
at next (D:\programmeer stuff\javascript\informatica site\New folder\node_modules\express\lib\router\index.js:280:10) {
code: 'ER_EMPTY_QUERY',
errno: 1065,
sqlMessage: 'Query was empty',
sqlState: '42000',
index: 0,
sql: undefined
}
The code I try to run is:

controllers/register.js

const db = require("../routes/db-config");
const bcrypt =require("bcryptjs")

const register = async (req, res) => {
const {email, password: Npassword} = req.body
if(!email || !Npassword) return res.json({satus:'error', error:"Please enter your email and password"});
else{
console.log(email);
db.query('SELECT email FROM users WHERE email = ?' , async(err, result) =&gt; { if(err) throw err; if(result[0])return res.json({satus:&#039;error&#039;, error:&quot;email already in use&quot;}) else { const password = bcrypt.hash(Npassword, 8); console.log(password) db.query(&#039;INSERT INTO users SET ?&#039;, {email: email, password: password}, (error, results)=&gt;{ if (error) throw error; return res.json({ satus:&quot;success&quot;, success:&quot;account registred succesfully&quot; }) }) } }) } } module.exports = register; I think either db.query(&#039;INSERT INTO users SET ?&#039;, {email: email, password: password}, (error, results)=&gt; or `db.query(&#039;SELECT email FROM users WHERE email = ?&#039;

Options: ReplyQuote


Subject
Written By
Posted
Error: ER_EMPTY_QUERY: Query was empty
December 24, 2022 06:24AM


Sorry, you can't reply to this topic. It has been closed.

Content reproduced on this site is the property of the respective copyright holders. It is not reviewed in advance by Oracle and does not necessarily represent the opinion of Oracle or any other party.