虽然这个问题非常...雄心勃勃,但您将获得什么作为答案...我将列出一些资源来帮助您入门...
请参阅 W3Schools 了解如何开始处理表单
https://www.w3schools.com/php/php_forms.asp
请参阅 MySQLi 以开始创建连接并执行“插入”语句到您的 MySQL 数据库
https://www.php.net/manual/en/book.mysqli.php
编辑:显然链接不是一个正确的答案......所以这是一个[正确] [edit2:但不准确的问题]答案......
<?php
if(isset($_POST) && count($_POST) > 0){
$link = mysqli_connect("127.0.0.1", "my_user", "my_password", "my_db");
$stmt = mysqli_prepare( $link, "INSERT INTO Location(Address, Latitude, Longitude) VALUES(?, ?, ?)");\
$stmt->bind_param("sdd", $_POST['Address'], $_POST['Latitude'], $_POST['Longitude']);
$stmt->execute();
}
?>
<html>
<body>
<form action='#' method='POST'>
<input name='Address' type='text' />
<input name='Latitude' type='text' />
<input name='Longitude' type='text' />
</form>
</body>
</html>
编辑 2:这是来自 Google 的地理编码(您需要有一个 Google Api 密钥,可以在这里找到:https://cloud.google.com/maps-platform/?apis=maps)
<?php
if(isset($_POST) && count($_POST) > 0){
//Initate Curl
$ch = curl_init();
//GeoCoding Address
$Google_API_KEY = "*****************";
$url = "https://maps.googleapis.com/maps/api/geocode/json?key={$Google_API_KEY}&address=" . urlencode($_POST['Address']) . "&sensor=false";
//Handle the Curl Params
curl_setopt($ch, CURLOPT_URL, $url);
curl_setopt($ch, CURLOPT_RETURNTRANSFER, 1);
//Execute Curl and Decode JSON
$response = json_decode(curl_exec($ch), true);
//var_dump($response);
$geometry = $response['results'][0]['geometry'];
$longitude = $geometry['location']['lat'];
$latitude = $geometry['location']['lng'];
$link = mysqli_connect("127.0.0.1", "my_user", "my_password", "my_db");
$stmt = mysqli_prepare( $link, "INSERT INTO Location(Address, Latitude, Longitude) VALUES(?, ?, ?)");
$stmt->bind_param("sdd", $_POST['Address'], $latitude, $longitude );
$stmt->execute();
}
?>
<html>
<body>
<form action='tester.php' method='POST'>
<input name='Address' type='text' />
</form>
</body>
</html>
请见谅
编辑 3:我不确定为什么这“过于宽泛”。但是,我想说这个问题缺少对他们所尝试的任何尝试......但是,如果他们确实尝试了两天,那么让我们解码用户所说的话......
(1)如何将php地理编码地址插入mysql数据库
- 在我的代码中,我展示了如何将地理编码地址插入 mysql 数据库
(2) 我有像 id、地址、纬度、经度这样的字段
(3) 我也不想设置硬编码的数据,我想通过 html 表单发送它,但表单应该只有 1 个文本输入用于地址
- 关于流程应该是什么以及在 html 中输入 1 个文本的要求的说明
(4) 它应该存储在数据库中的不同字段中,例如:我在输入字段中输入地址,它应该插入数据库地址字段以及纬度和经度
- 在我的代码中,确实是先查找地址,然后将经纬度输入数据库
(5) 也应该在搜索的同时存储
(6) 超过 2 天,但未找到任何结果,将不胜感激。
由于这被认为是在互联网上寻求编码帮助的最佳地点,我想见鬼,为什么不帮助 [新] 用户。无论如何,我相信我确实回答了用户提出的 [消除歧义] 问题