2

This is my index page for my geo location page

<!DOCTYPE html>
<html>
<head>
<script src="js/jquery.js"></script>
</head>

<body>
<script>
setInterval ( "onPositionUpdate()", 10000 );

var currPosition;
navigator.geolocation.getCurrentPosition(function(position) {
    updatePosition(position);
    setInterval(function(){
        var lat = currPosition.coords.latitude;
        var lng = currPosition.coords.longitude;
        $.ajax({
            type: "POST", 
            url:  "myURL/location.php", 
            data: 'x='+lat+'&y='+lng, 
            cache: false
        });
    }, 2000);
}, errorCallback); 

var watchID = navigator.geolocation.watchPosition(function(position) {
    updatePosition(position);
});

function updatePosition( position ){
    currPosition = position;
}

function errorCallback(error) {
    var msg = "Can't get your location. Error = ";
    if (error.code == 1)
        msg += "PERMISSION_DENIED";
    else if (error.code == 2)
        msg += "POSITION_UNAVAILABLE";
    else if (error.code == 3)
        msg += "TIMEOUT";
    msg += ", msg = "+error.message;

    alert(msg);
}
</script>
</body>
</html>

This is my location.php page

<?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->prepare($sql);
  $q->execute(array($x),($y));

?>

This is my config.php page

<?php
$dbtype     = "";
$dbhost     = "localhost";
$dbname     = "test";
$dbuser     = "root";
$dbpass     = "";

?>

The problem is when i am on my xampp testing my geo location out i keep getting a error Warning: PDOStatement::execute() expects at most 1 parameter, 2 given in C:\xampp\htdocs\project_track\myURL\location.php on line 15

I am trying to make a app that tracks my location and upload it to my database i been working on this project for some time hopefully i am on the right track i would like to know what do i do to correct this problem can some one please help...how should i set my database up for this i would like my app to record a username and lat and long and save it to my database and retrieve it so i can use it for google maps please help me with this...

Is my Sql wrong

1 Answer 1

3

Your execute line should be:

$q->execute(array($x, $y));

Isn't it ? The Input parameter should be in form of array, but you supplied 2 parameters, one is array, the other one is a variable.

Also, the SQL is incorrect. It should be:

update locations set x=?, y=? where username = 'asd'

Reference: http://php.net/manual/en/pdostatement.execute.php

Sign up to request clarification or add additional context in comments.

8 Comments

Ok that work but how come im not seeing my sql database update with my lat and long...
It's because your SQL is incorrect. Your username value should be quoted with single quotes. Even better, use primary key ID to update instead of using text.
im confused what code are your talking about where it should be single qouted
Ok i have change the line to what your have said but i am not seeing no update in my sql at all
what is the content of $x and $y ? You should post the resultant SQL statement.
|

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.