我创建了一个 android 应用程序,用于将数据上传到我的网络服务器到 PHP 文件中并将数据输出到.txt
文件中。我升级了我的服务器,现在我支持数据库。
如何转换/更新以下 php 代码以连接 MySQL 数据库?在 android 端使用 HTTP POST 到 url mysite/location.php 我想将记录纬度,经度添加到我的数据库...mysql查询...需要代码示例...
<?php
$lat = $_POST["lat"]; // Declares the upload data from client as a variable
$lon = $_POST["lon"];
$textfile = "location.txt"; // Declares the name and location of the .txt file
$fileLocation = "$textfile";
$fh = fopen($fileLocation, 'w ') or die("Something went wrong!"); // Opens up the .txt file for writing and replaces any previous content
$stringToWrite = " $lat\n $lon\n "; // Write location
fwrite($fh, $stringToWrite); // Writes it to the .txt file
fclose($fh);
//header("Location: index.html"); // Return to frontend (index.html)
?>