Reputation: 581
I'm trying to figure out how to store the ID number, lat and lng to a database. Primarily with this array below. I'm looking to have all the markers add to the database once you hit save, and each marker that I removed when pressing the remove button, be removed from the database.
To add markers I used:
$("#marker").click(function () {
map.on('click', onMapClick);
var markers = new Array();
function onMapClick(e) {
var marker = new L.Marker(e.latlng, {draggable:false});
map.addLayer(marker);
markers[marker._leaflet_id] = marker;
$('#overlay > ul').append('<li>Marker '+ marker._leaflet_id + ' - <a href="#" class="remove" id="' + marker._leaflet_id + '">remove</a></li>');
console.log(marker._leaflet_id + "," + e.latlng.lat + "," + e.latlng.lng);
$("#savemarkers").on("click", function(){
console.log(marker._leaflet_id + "," + e.latlng.lat + "," + e.latlng.lng);
//save all the markers lat and lng to db
});
// Remove a marker
$('.remove').on("click", function() {
// Remove the marker
map.removeLayer(markers[$(this).attr('id')]);
// Remove the link
$(this).parent('li').remove();
});
My table in MySQL goes as ID, username, password, Lat, Lng, Email
Inside my db_const.php I have
<?php
# mysql db constants DB_HOST, DB_USER, DB_PASS, DB_NAME
const DB_HOST = 'localhost';
const DB_USER = 'root';
const DB_PASS = '######';
const DB_NAME = '#######';
?>
Upvotes: 0
Views: 1130
Reputation: 14649
First off require_once("db_const.php");
is not JS, and is PHP so you need to add the necessary replacement to that file. Furthermore, if you are not defining a constant in a class, then your syntax is invalid. Please look at the docs. http://www.php.net/manual/en/language.constants.php
You define constants outside of class with the define()
method.
Upvotes: 1