gpt4 book ai didi

jquery - 不断收到错误警告:PDOStatement::execute() 最多需要 1 个参数,2 个在 config.php 第 15 行中给出

转载 作者:行者123 更新时间:2023-12-01 03:42:38 25 4
gpt4 key购买 nike

这是我的地理位置页面的索引页

<!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页面

<?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 页面

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

?>

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

我正在尝试制作一个应用程序来跟踪我的位置并将其上传到我的数据库我已经在这个项目上工作了一段时间希望我走在正确的轨道上我想知道我该怎么做才能纠正这个问题可以请有人帮忙...我应该如何为此设置我的数据库我希望我的应用程序记录用户名和纬度和经度并将其保存到我的数据库中并检索它以便我可以将它用于谷歌地图请帮助我这...

我的Sql错误吗

最佳答案

您的执行行应该是:

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

不是吗?输入参数应为数组形式,但您提供了 2 个参数,一个是数组,另一个是变量。

此外,SQL 也不正确。应该是:

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

引用:http://php.net/manual/en/pdostatement.execute.php

关于jquery - 不断收到错误警告:PDOStatement::execute() 最多需要 1 个参数,2 个在 config.php 第 15 行中给出,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/17779649/

25 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com