0

I am trying to create a basic form where the user can enter his name, a comment and click on a submit button. When user clicks on submit, his name, comment as well as geolocation (longitude + latitude) are stored in a database. I have only one problem: How can I store the javascript variable of his geolocation into the database?

I have two php files. Iamhere.php (gets the data) and Iamhere_post.php (insert data into database).

4

2 回答 2

1

在表单中填充包含所需值的隐藏字段。

创建字段经度 + 纬度,然后使用 javascript 用地理值填充它们,以便它们与表单一起提交

于 2013-04-24T01:24:55.067 回答
0

在 HTML 表单中为每个纬度和经度填充一个隐藏字段:

<input type='hidden' name='latitude' />
<input type='hidden' name='longitude' />

将您的地理位置存储到变量中并将该变量添加到隐藏字段:

var latitude; //store the latitude to this variable.
var longitude; //store the longitude to this variable.

document.getElementsByName("latitude")[0].setAttribute("value",latitude)
document.getElementsByName("longitude")[0].setAttribute("value",longitude)

像往常一样在数据库插入中使用 PHP 脚本调用它:

$_POST['latitude'];
$_POST['longitude'];
于 2013-04-24T01:32:00.787 回答