> You could set 2 hidden fields in your form:
> GEvent.addListener(map, "click", function(overlay, latlng) {
> if (latlng) {
> marker = new GMarker(latlng, {draggable:true});
> var latlng = marker.getLatLng();
> var lat = latlng.lat();
> var lng = latlng.lng();
> GEvent.addListener(marker, "click", function() {
> var html ="<form method='post' enctype='multipart/form-data'
> action='up_addrow.php'>
> <input type='hidden' name='lat' value='"+lat+"' />
> <input type='hidden' name='lng' value='"+lng+"' /> .......
> Because you already have the marker in the click function, you can get
> the lat / lng from it and pass that into your form.
> Your save data function returns 0 for the lat / lng because "marker"
> isn't a global variable, hence you can't call marker.getLatLng().
> Hope this helps you on your way
> Alex Holsgrove
> Donal wrote:
> > Hi all
> > Am having a problem passing latitude and longitude to a php script
> > which then writes to a database.
> > Basically what I'm trying to do is allow a user to upload a
> > file(video) inside a marker infowindow via a php script. I am using
> > the google writing to a database tutorial code modified to enable
> > uploads.
> > Code for the map and php script is below.....I think the problem lies
> > with the fact that the html form is calling up_addrow.php and then
> > calling the saveData() function which also tries to call
> > up_addrow.php. The uploads are making it to the database fine but the
> > lat&lng are not and are populated with zeros.
> > Any help would be much appreciated
> > //MAP
> > function initialize() {
> > if (GBrowserIsCompatible()) {
> > var map = new GMap2(document.getElementById("map_canvas"));
> > map.setCenter(new GLatLng(37.4419, -122.1419), 13);
> > GEvent.addListener(map, "click", function(overlay, latlng) {
> > if (latlng) {
> > marker = new GMarker(latlng, {draggable:true});
> > GEvent.addListener(marker, "click", function() {
> > var html ="<form method='post' enctype='multipart/form-
> > data' action='up_addrow.php'>"+
> > "<table width='350' border='0' cellpadding='1' cellspacing='1'>"+
> > "<tr>"+
> > "<td width='246'>"+
> > "<input type='hidden' name='MAX_FILE_SIZE' value='2000000'>"+
> > "<input name='userfile' type='file' id='userfile'>"+
> > "</td>"+
> > "<td width='80'><input name='upload' type='submit' class='box'
> > id='upload' value='Upload' onSubmit='saveData()'></td>"+
> > "</tr>"+
> > "</table>"+
> > "</form>";
> > marker.openInfoWindow(html);
> > });
> > map.addOverlay(marker);
> > }
> > });
> > }
> > }
> > function saveData() {
> > var latlng = marker.getLatLng();
> > var lat = latlng.lat();
> > var lng = latlng.lng();
> > var url = "up_addrow.php?lat=" + lat + "&lng=" + lng;
> > GDownloadUrl(url, function(data, responseCode) {
> > if (responseCode == 200 && data.length <= 1) {
> > marker.closeInfoWindow();
> > document.getElementById("message").innerHTML = "Location
> > added.";
> > }
> > });
> > }
> > </script>
> > //PHP SCRIPT
> > <?php
> > require("up_dbinfo.php");
> > if(isset($_POST['upload']) && $_FILES['userfile']['size'] > 0)
> > {
> > $fileName = $_FILES['userfile']['name'];
> > $tmpName = $_FILES['userfile']['tmp_name'];
> > $fileSize = $_FILES['userfile']['size'];
> > $fileType = $_FILES['userfile']['type'];
> > // Gets data from URL parameters
> > $lat = $_GET['lat'];
> > $lng = $_GET['lng'];
> > if(!get_magic_quotes_gpc())
> > {
> > $fileName = addslashes($fileName);
> > }
> > include 'library/config.php';
> > include 'library/opendb.php';
> > // Opens a connection to a MySQL server
> > $connection=mysql_connect ("localhost", $username, $password);
> > if (!$connection) {
> > die('Not connected : ' . mysql_error());
> > }
> > // Set the active MySQL database
> > $db_selected = mysql_select_db($database, $connection);
> > if (!$db_selected) {
> > die ('Can\'t use db : ' . mysql_error());
> > }
> > $query = "INSERT INTO upload (name, size, type, content,lat, lng ) ".
> > "VALUES ('$fileName', '$fileSize', '$fileType', '$content', '$lat',
> > '$lng')";
> > mysql_query($query) or die('Error, query failed');
> > include 'library/closedb.php';
> > echo "<br>File $fileName uploaded<br>";
> > }
> > ?>