I want to store data into mysql table using JavaScript. But, I don't want to use php. Is it possible?
Asked
Active
Viewed 966 times
0
-
See here: http://stackoverflow.com/questions/3020751/can-javascript-connect-with-mysql – Nikhil May 03 '17 at 06:13
-
you might want to use node js that might help you interact with the server using java script – Rahul Singh May 03 '17 at 06:16
-
You can use any language you want on the server side. – Felix Kling May 03 '17 at 06:19
-
Just curious: why not php? – Strawberry May 03 '17 at 07:11
-
Possible duplicate of [Can JavaScript connect with MySQL?](http://stackoverflow.com/questions/3020751/can-javascript-connect-with-mysql) – mbdevpl May 03 '17 at 08:24
-
Strawberry: This maybe very stupid, but when I try to access the index.php page, the browser tries to download it as opposed to opening it. I hope might understood what I meant. – Jahangir May 04 '17 at 05:11
3 Answers
1
Javascript is a client-side language, so it runs on the clients browser. If you still want to insert into mysql using javascript then you could use something like node.js which would run on the server-side.
For instance this is how an insert using node.js would look like:
var post = {id: 1, title: 'Hello MySQL'};
var query = connection.query('INSERT INTO posts SET ?', post, function(err, result) {
// check result or error!
});

lloiacono
- 4,714
- 2
- 30
- 46
-
actually I want to use it only for like counter, I mean i want to increment in like counter. I hope you might understand what I want to do .. further is it a good approach to use node.js for only like counter ? – Jahangir May 03 '17 at 09:56
-
-
0
Jahangir jan, It's not possible to use client side Javascript to store something into the MySQL. But it's possible to use server side Javascript to do it.

Hossein
- 2,592
- 4
- 23
- 39
-
Yes nodejs is a server side Javascript language so you can communicate with database as well. – Hossein May 03 '17 at 09:59