Biggest
Biggest

Reputation: 671

How to store data into a mysql database using javascript?

I'm still pretty new to AJAX. We have a MySQL database that stores addresses for people who register with the site. We then use those stored addresses to create markers on a Google Map (API v3) through a JSON query. The problem is, that's pretty slow, and limited in the number of queries we're allowed. So we've created fields in the database to store the latitude and longitude that is being called by JSON.

Through each pass of the loop, the numbers can be retrieved through

result[0].geometry.location.lat() result[0].geometry.location.lng()

How do I take those numbers and store them into their empty fields in the database?

Upvotes: 4

Views: 8532

Answers (2)

Ozzy
Ozzy

Reputation: 8312

You can send data to a server with javascript, but you need a library to interact with a database system, so on the server you will usually process that data and send commands to store it in the database. In PHP the support for MySQL is built-in so you have functions and objects to connect to the database simply like mysql_XXXX or through a PDO object.

http://php.net/manual/en/book.pdo.php

Upvotes: 2

Najzero
Najzero

Reputation: 3202

Javascript runs on the client/browser side - its not a good idea to give that access to your mysql-server/databases.

Just use some server-side logic (php) for that.

Heres an example from W3 retrieving data via AJAX and PHP, just change to updating stuff

http://www.w3schools.com/php/php_ajax_database.asp

Upvotes: 4

Related Questions