[英]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.