[英]How can I connect android uploads PHP data with MySQL database?
我创建了一个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)
?>
这是一个相当广泛的问题。 简而言之,我会这样做:
一般来说,我会建议不要针对特定的设计问题“找一个教程”,因为你想要的具体解决方案可能以前没有完成。 但是,它的组成部分; 因此,如果你打破问题 ,你会发现每一点都更容易管理。
所以,首先,搜索这个网站的“ HTTP库POST Android ”,这肯定会返回许多代码示例。 实现它,并确保它正在工作,并且广泛地说,你理解它。 接下来,在搜索引擎中尝试“ PHP MySQL PDO insert ”,并使其正常工作,然后重复此过程直到您的项目完成。
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.