本文介绍了不断收到错误警告:PDOStatement :: execute()最多期望1个参数,config.php第15行中给出的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>

这是我的location.php页面

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));

?>

这是我的config.php页面

This is my config.php page

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

?>

问题是当我在xampp上测试地理位置时我不断收到错误警告:PDOStatement :: execute()最多期望1个参数,第15行的C:\ xampp \ htdocs \ project_track \ myURL \ location.php中给出2个参数

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...

我的Sql错误吗

推荐答案

您的执行行应为:

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

不是吗? Input参数应采用数组形式,但是您提供了2个参数,一个是array,另一个是变量.

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.

此外,SQL不正确.应该是:

Also, the SQL is incorrect. It should be:

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

参考: http://php.net/manual/en/pdostatement.execute. php

这篇关于不断收到错误警告:PDOStatement :: execute()最多期望1个参数,config.php第15行中给出的2个参数的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持!

10-31 12:32