This function is in a PHP file, but is full of JS code. The last line passes the data to another PHP file which saves the data into a database.
    function  saveProfile (){
      var _profileId    = 0;
      var _profileName  = document.getElementById('nameProfile').value;
        var queryArr=[];
       $(markersArray).each(function (index){
            //alert(markersArray[index].name);
            var _locationId = index;
            var _locName    = markersArray[index].name;
            var _markerLat  = markersArray[index].marker.getLatLng().lat();
            var _markerLng  = markersArray[index].marker.getLatLng().lng();
            var locations = {  
                                profileName: _profileName,
                                locationId:_locationId,
                                locationName:_locName,
                                lat:_markerLat,
                                lng:_markerLng  }
            queryStr = { "locations": locations} 
            queryArr.push(queryStr);
        });
        /*for ( var i=0; i<markersArray.length; i++){
            alert(queryArr[i].locations.locationId+"--"+queryArr[i].locations.locationName +"--"+queryArr[i].locations.lat);
        }*/
          $.post('dbConn.php', { opType:"saveAsProfile" , data: queryArr}, showResult, "text");
    }
This is dbConn.php, which is called by the saveProfile method. The data is handled as follows:
    $db_host = 'localhost';
    $db_user = 'root';
    $db_pass = '';
    $db_name = 'google_map_db';
    $opType = $_POST['opType'];
    //SAVE PROFILES WITH A PROFILE NAME
    if(!strcmp($opType, "saveAsProfile") ){
        $res = $_POST['data'];
        $connect = mysql_connect( $db_host, $db_user, $db_pass ) or die( mysql_error() );
        mysql_select_db( $db_name ) or die( mysql_error() );
        $queryString = "";
        for($i = 0; $i < sizeof($res); $i++){
            $profileName  = $res[$i]['locations']['profileName'];
            $locationId   = $res[$i]['locations']['locationId'];
            $locationName = $res[$i]['locations']['locationName'];
            $lat          = $res[$i]['locations']['lat'];
            $lng          = $res[$i]['locations']['lng'];
            $sp = " ";
            $queryString =  $queryString . "(0 ".",'".$profileName."',".$locationId.",'".$locationName."',".$lat.",".$lng.") ";
            if($i<sizeof($res)-1)
                $queryString =  $queryString . ", ";
        }
        $qInsertUser = mysql_query(" INSERT INTO `map_locations` (`profileId`, `profileName`, `locationId`, `locationName`, `lat`, `lng`)
                                     VALUES  ".$queryString." ");
        if ($qInsertUser){
            echo "successfully added!!!";
        } else {
            echo "Error";
        }
    }
     
    
dbConn.php?