title: How can I connect android uploads PHP data with MySQL database?
body: <p>I created an android application for uploads data to my webserver into PHP file and output data to <code>.txt</code> file. I upgraded my server and now I support databases.</p>
  
  <p>How can I convert/update the below php code toconnect with a MySQL database? In android side use HTTP POST to url mysite/location.php
  I want add records latitude,longitude to my database...mysql query...need code example...</p>
  
  <pre><code>&lt;?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)
  ?&gt;
  </code></pre>