Is it possible to add a JavaScript variable in an SQL Server database database (run an SQL query or stored procedure)? If so, how?
-
1not sure what you mean - I would think you can insert whatever value you can output - can you explain with a little more detail?M.R.– M.R.2011-05-03 04:56:11 +00:00Commented May 3, 2011 at 4:56
-
i want save value of some javascript variable within a function in sql server database. like save last position of one image that changed by user.hamze torabzade– hamze torabzade2011-05-03 04:59:19 +00:00Commented May 3, 2011 at 4:59
-
I see this question almost everyday now on SO.Jasdeep Singh– Jasdeep Singh2011-05-03 05:02:51 +00:00Commented May 3, 2011 at 5:02
-
Is this question restricted to Microsoft SQL Server or is it for any SQL database?Peter Mortensen– Peter Mortensen2012-11-21 17:30:31 +00:00Commented Nov 21, 2012 at 17:30
5 Answers
With JavaScript only, no you cannot (unless you're using Node.js of course).
The point is, you'll need some server-side code to interact with your database. You can use JavaScript in the browser to make an Ajax call to a server-side script (PHP, Ruby, Python, ASP.NET, Node.js, etc.) that performs the interaction with the database.
1 Comment
You can not access the database from JavaScript. You need to send your data to PHP, Ruby on Rails or ASP.NET or whatever you are using to implement the back end.
2 Comments
Set value of variable in the hidden field and get value of that field at server side when submit form and save it into the database....
1 Comment
You can easily access a database from JavaScript in Node.js.
If you're doing it from the browser, you'll most definitely need some kind of mid-tier service which translates HTTP queries to the relevant database driver (you can write that in any language you want - PHP, JavaScript, ASP.NET, etc.).