Jump to content

NodeJS SQL Insert Query isn't working, why?

Go to solution Solved by keskparane,

how do you spell INSERT? ;)

Hello,

i want to create a login system.

My code isn't adding anything into the Table, it also doesn't throw any errors.

try{
  conn = await conn_sql.getConnection();
  await conn.query(`INSERNT INTO user (username,password) VALUES ('${data.username}','${data.password}')`);
}catch(err){
  throw err;
}finally{
  if(conn) return conn.end();
}

 

AMD FX8320 | GTX660 | 4x4GB DDR3 | LG ZR2740W

Logitech Wireless Pro  | Logitech G413 | Nuforce uDAC5  | AKG K612

Link to comment
https://linustechtips.com/topic/1000478-nodejs-sql-insert-query-isnt-working-why/
Share on other sites

Link to post
Share on other sites

I know you're just getting started with a login, and I 100% approve of starting with the bare minimum and working your way up, but I do want to just point out that if you are just storing passwords in the database in plaintext like that, you are not making a secure login. That may not matter at all to you, which is fine, just figured i'd point it out in case this grows into something where security might have an impact.

Gaming build:

CPU: i7-7700k (5.0ghz, 1.312v)

GPU(s): Asus Strix 1080ti OC (~2063mhz)

Memory: 32GB (4x8) DDR4 G.Skill TridentZ RGB 3000mhz

Motherboard: Asus Prime z270-AR

PSU: Seasonic Prime Titanium 850W

Cooler: Custom water loop (420mm rad + 360mm rad)

Case: Be quiet! Dark base pro 900 (silver)
Primary storage: Samsung 960 evo m.2 SSD (500gb)

Secondary storage: Samsung 850 evo SSD (250gb)

 

Server build:

OS: Ubuntu server 16.04 LTS (though will probably upgrade to 17.04 for better ryzen support)

CPU: Ryzen R7 1700x

Memory: Ballistix Sport LT 16GB

Motherboard: Asrock B350 m4 pro

PSU: Corsair CX550M

Cooler: Cooler master hyper 212 evo

Storage: 2TB WD Red x1, 128gb OCZ SSD for OS

Case: HAF 932 adv

 

Link to post
Share on other sites

7 hours ago, reniat said:

I know you're just getting started with a login, and I 100% approve of starting with the bare minimum and working your way up, but I do want to just point out that if you are just storing passwords in the database in plaintext like that, you are not making a secure login. That may not matter at all to you, which is fine, just figured i'd point it out in case this grows into something where security might have an impact.

This assumes that this data.password isn't hashed before being put into this function.

 

8 hours ago, G1K777 said:

Hello,

i want to create a login system.

My code isn't adding anything into the Table, it also doesn't throw any errors.


try{
  conn = await conn_sql.getConnection();
  await conn.query(`INSERNT INTO user (username,password) VALUES ('${data.username}','${data.password}')`);
}catch(err){
  throw err;
}finally{
  if(conn) return conn.end();
}

 

other then the spelling on INSERT you should check the module you are using actually returns a promise you can await on.
 

                     ¸„»°'´¸„»°'´ Vorticalbox `'°«„¸`'°«„¸
`'°«„¸¸„»°'´¸„»°'´`'°«„¸Scientia Potentia est  ¸„»°'´`'°«„¸`'°«„¸¸„»°'´

Link to post
Share on other sites

10 hours ago, keskparane said:

how do you spell INSERT? ;)

Thank you, you know how it is.. when you code from 7pm till 7am and start making simple mistakes that you don't see.

AMD FX8320 | GTX660 | 4x4GB DDR3 | LG ZR2740W

Logitech Wireless Pro  | Logitech G413 | Nuforce uDAC5  | AKG K612

Link to post
Share on other sites

2 hours ago, G1K777 said:

when you code from 7pm till 7am and start making simple mistakes that you don't see.

This is why overworking engineers doesn't lead to good code. Sleep is good for code quality :D 

Gaming build:

CPU: i7-7700k (5.0ghz, 1.312v)

GPU(s): Asus Strix 1080ti OC (~2063mhz)

Memory: 32GB (4x8) DDR4 G.Skill TridentZ RGB 3000mhz

Motherboard: Asus Prime z270-AR

PSU: Seasonic Prime Titanium 850W

Cooler: Custom water loop (420mm rad + 360mm rad)

Case: Be quiet! Dark base pro 900 (silver)
Primary storage: Samsung 960 evo m.2 SSD (500gb)

Secondary storage: Samsung 850 evo SSD (250gb)

 

Server build:

OS: Ubuntu server 16.04 LTS (though will probably upgrade to 17.04 for better ryzen support)

CPU: Ryzen R7 1700x

Memory: Ballistix Sport LT 16GB

Motherboard: Asrock B350 m4 pro

PSU: Corsair CX550M

Cooler: Cooler master hyper 212 evo

Storage: 2TB WD Red x1, 128gb OCZ SSD for OS

Case: HAF 932 adv

 

Link to post
Share on other sites

2 hours ago, G1K777 said:

Thank you, you know how it is.. when you code from 7pm till 7am and start making simple mistakes that you don't see.

amen

If you're interested in a product please download and read the manual first.

Don't forget to tag or quote in your reply if you want me to know you've answered or have another question.

Link to post
Share on other sites

How can i prevent all forms from default submission? I want to use AJAX on all forms.
I was trying and trying things but Javascript doesn't look like they like to make coding easier...

Why i can't just do the following? (doesn't work, it still submits the form.)

let form = document.getElementsByTagName("form");
form.addEventListener("submit", function(event){
	event.preventDefault()
});

 

AMD FX8320 | GTX660 | 4x4GB DDR3 | LG ZR2740W

Logitech Wireless Pro  | Logitech G413 | Nuforce uDAC5  | AKG K612

Link to post
Share on other sites

Create an account or sign in to comment

You need to be a member in order to leave a comment

Create an account

Sign up for a new account in our community. It's easy!

Register a new account

Sign in

Already have an account? Sign in here.

Sign In Now

×