【发布时间】:2019-10-02 04:24:04
【问题描述】:
我在我的项目中使用 Mapbox,我想知道如何从输入搜索自动完成中获取地址并使用 php 在 Mysql 表中插入这个地址?我试图找到与我的疑问类似的东西,但我没有找到。以下是我试图找到答案的一些问题:
- Mapbox - Can I use the locationlistener without Mapbox map
- Custom Mapbox Geocoder Control
- Retrieve data from mapbox geocoder
在这种情况下,我有一个如下表:
表用户
id | username | address | City
==============================================
01 | John | abc street | New York
02 | Joseph | Marie Street | Washington
03 | Amy | Barkley street | Houston
在我的表单中,我有 3 个字段将数据发送到用户表。下面的 HTML 代码显示了表单结构:
<form action="" id="register_user">
<label for="username">Username</label>
<input type="text" id="Username" name="Username" placeholder="Your Username..">
<label for="address">address</label>
<input type="text" id="address" name="address" placeholder="Your address..">
<input type="submit" value="Submit" >
</form>
在我的 php 插入脚本中,我有一个函数可以将输入表单中的值插入到 users 表:
if(isset($_GET['add_location'])) {
add_location();
}
function add_location(){
$con=mysqli_connect ("localhost", 'root', '','system');
if (!$con) {
die('Not connected : ' . mysqli_connect_error());
}
$username= $_GET['username'];
$address = $_GET['address'];
// Inserts new row with place data.
$query = sprintf("INSERT INTO users " .
" (id, username, address) " .
" VALUES (NULL, '%s', '%s');",
mysqli_real_escape_string($con,$username),
mysqli_real_escape_string($con,$address));
$result = mysqli_query($con,$query);
echo json_encode("Inserted Successfully");
if (!$result) {
die('Invalid query: ' . mysqli_error($con));
}
}
下面的图片正是我需要的,但我不知道该怎么做:
上面的例子可以做吗?谢谢:)
【问题讨论】: