Note that there are some explanatory texts on larger screens.

plurals
  1. POSend user's geolocation to server every minute
    primarykey
    data
    text
    <p>I'm trying to write a application that sends user's geolocation to MYSQL database every minute or so. This is the code I have right now, but it's not working. How do i need to change this to make it work?</p> <p>JS:</p> <pre><code>&lt;!DOCTYPE html&gt; &lt;html&gt; &lt;head&gt; &lt;script src="js/jquery.js"&gt;&lt;/script&gt; &lt;/head&gt; &lt;body&gt; &lt;script&gt; setInterval ( "onPositionUpdate()", 10000 ); function onPositionUpdate(position) { var lat = position.coords.latitude; var lng = position.coords.longitude; jQuery.ajax({ type: "POST", url: "myURL/location.php", data: 'x='+lat+ '&amp;y='+lng , cache: false, }); } if(navigator.geolocation) navigator.geolocation.watchPosition(onPositionUpdate); else alert("navigator.geolocation is not available"); &lt;/script&gt; &lt;/body&gt; &lt;/html&gt; </code></pre> <p>and PHP:</p> <pre><code>&lt;?php include 'config.php'; // database connection $conn = new PDO("mysql:host=$dbhost;dbname=$dbname",$dbuser,$dbpass); // new data $x = @$_POST['x']; $y = @$_POST['y']; // query $sql = "update locations set x=?, y=? where username = asd"; $q = $conn-&gt;prepare($sql); $q-&gt;execute(array($x), ($y)); ?&gt; </code></pre> <p>And I suppose this is not the right way to send multiple variables, is it?. Firebug's console shows me</p> <pre><code> missing } after property list [Break On This Error] data: 'x='+lon+'&amp;y='+lat; </code></pre> <p>When I use only one value, it POSTs that variable to server only once and after that console gives:</p> <pre><code>position is undefined [Break On This Error] var lat = position.coords.latitude; </code></pre>
    singulars
    1. This table or related slice is empty.
    plurals
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. This table or related slice is empty.
 

Querying!

 
Guidance

SQuiL has stopped working due to an internal error.

If you are curious you may find further information in the browser console, which is accessible through the devtools (F12).

Reload