That did not work
Here is a better description with ALL of the details
I have a table in dadabik called 'geo'
It has fields for name, user id, time date stamp, latitude and longitude (and some other fields).
I have a javascript file called 'geoloc.js' which retrieves the users latitude and longitude from their device.
Stand-alone, called from an index.php page,
It works fine as a 'stand-alone" function (outside of dadabik).
geoloc.js code:
(function() {
window.onload = getLocation;
var geo = navigator.geolocation;
function getLocation() {
if (geo) {
geo.getCurrentPosition(displayLocation);
} else {
alert("Geolocation API is not supported");
}
}
function displayLocation(position) {
var lat = position.coords.latitude;
var lang = position.coords.longitude;
document.getElementById('txtlat').value = lat;
document.getElementById('txtlang').value = lang;
}
}());
I then can externally insert the latitude and longitude into the table with no problem.
The external insertdb.php code is:
<?php
$con = mysqli_connect("localhost", "user", "pw", "dbname");
if (mysqli_connect_errno()) {
echo "Failed to connect to MySQL: " . mysqli_connect_error();
}
$latitude = $_REQUEST['txtlat'];
$longitude = $_REQUEST['txtlang'];
$name = $_REQUEST['txt_name'];
$dob = $_REQUEST['txt_dob'];
$state = $_REQUEST['txt_state'];
$city = $_REQUEST['txt_city'];
$phn = $_REQUEST['txt_phno'];
$zip = $_REQUEST['txt_zip'];
$ipaddress = '';
if (isset($_SERVER['HTTP_CLIENT_IP']))
$ipaddress = $_SERVER['HTTP_CLIENT_IP'];
else if (isset($_SERVER['HTTP_X_FORWARDED_FOR']))
$ipaddress = $_SERVER['HTTP_X_FORWARDED_FOR'];
else if (isset($_SERVER['HTTP_X_FORWARDED']))
$ipaddress = $_SERVER['HTTP_X_FORWARDED'];
else if (isset($_SERVER['HTTP_FORWARDED_FOR']))
$ipaddress = $_SERVER['HTTP_FORWARDED_FOR'];
else if (isset($_SERVER['HTTP_FORWARDED']))
$ipaddress = $_SERVER['HTTP_FORWARDED'];
else if (isset($_SERVER['REMOTE_ADDR']))
$ipaddress = $_SERVER['REMOTE_ADDR'];
else
$ipaddress = 'UNKNOWN';
$ip = $ipaddress;
$SLNO = "100001";
$sqlres = "select MAX(id) from `geo`";
if ($result = mysqli_query($con, $sqlres)) {
if ($row = mysqli_fetch_array($result)) {
if ($row[0] != "") {
$SLNO = $row[0] + 1;
}
}
mysqli_free_result($result);
} $now = date("Y-m-d H:i:s");
mysqli_query($con, "INSERT INTO `geo` (`id`,`sdate`,`lat`,`long`,`ip_add`,`name`,`DOB`,`state`,`city`,`phone_no`,`zip`) VALUES ('$SLNO','$now','$latitude','$longitude','$ip','$name','$d>
echo "Data Saved Successfully";
echo '<form><input type="button" value="Return to previous page" onClick="javascript:history.go(-2)"></form>';
?>
How can i perform this function from within my dadabik form page?
I do not want to launch an external page for this function.
I just want to grab the lat and long using my geoloc.js script and insert the
values retrieved into my latitude and longitude fields of my form.
(should not be any need to use my external insertdb.php code)