Ive been trying to send gps data from my android app to a mysql database using php but Im not sure if everything is set up right because I can see through the logcat that the data is being sent from android but its just not getting sucked up by the database.
Aside from some recommendations does any body have any tutorials that would show specifically the php to server code.
Also is it possible to just send the data straight to the database without something like php? I dont think so but I had to ask.
here is the php that I am using with the addresses and stuff taken out for obvious reasons.
<html>
<head>
<title>Send and Rec data to Android Device</title>
<meta http-equiv="Content-Type" content="text/html; charset=iso-8859-1">
</head>
<body>
<?php
//include("dbinfo.php");
///the stuff pointing to my db has been removed for obvious ///reasons ;)
mysql_connect($hostname,$username,$password) or die ("<html><script
language='JavaScript'>alert('Unable to connect to database! Please try again later.'),history.go(-
1) </script></html>");
mysql_select_db($dbname);
// variables coming from Android app on phone
$id = $_POST["id"];
$lat = $_POST["lat"]; // If data is in DB line 1 (public key), but the publicly displayed PHP is
not showing data then we know that we aren't really talking to line 1
$lng = $_POST["lng"];
$alt = $_POST["alt"];
$spd = $_POST["spd"];
$acc = $_POST["acc"];
$last_gps = $_POST["lastgps"];
//filler will contain reference to graphic or audio upload directory
$filler = $_POST["filler"];
$lastid = mysql_query("select MAX(id) as maxid from samplemarks");
$row = mysql_fetch_array($lastid);
$nextid = $row[maxid] + 1;
echo "Inserting at next id = ".$nextid."<br />";
if ($lat == "")
{
echo "Invalid entry, latitude cannot be blank";
}
else {
$query2 = mysql_query("INSERT INTO samplemarks VALUES($nextid,'$lat',
$lng,'$alt','$spd','$acc','$last_gps','$filler')");
mysql_query($query2);
mysql_close();
}
?>
</body>
</html>
Your mysql_query is missing the connection parameter. When you do the connect, store it in a variable eg
Also $lng isn’t quoted in your code.
I realise that you are sending data from your android application to your php/db server but you should always sanity check the data from the post, otherwise you’re making it easy for someone to use sql injection attacks to compromise your database. Think about protecting your php with ssl and username/password