Hi everyone,
I have found many tutorials but I could not find the solution. Here is the code. In server side and in my app. My target is to save current location data to server after click to button. Only I need to save data if anyone knows easy way to save data I can try.
Thanks
I have found many tutorials but I could not find the solution. Here is the code. In server side and in my app. My target is to save current location data to server after click to button. Only I need to save data if anyone knows easy way to save data I can try.
Thanks
PHP:
<?
//include ("db.php");
$host = "*************";
$db = "************";
$user = "*********";
$pw = "********";
$con = mysql_connect($host,$user,$pw) or die(mysql_error());
mysql_select_db($db) or die(mysql_error());
mysql_query("SET CHARACTER SET utf8");
$action = $_GET["action"];
switch ($action)
{
case "InsertLocation":
$ID = $_GET["ID"];
$Vehicle = $_GET["Vehicle"];
$Time = $_GET["Time"];
$Date = $_GET["Date"]:
$Lat = $_GET["Lat"];
$Long = $_GET["Long"];
$q = mysql_query("INSERT INTO user_table (ID, Vehicle,Time,Date,Lat,Long) VALUES ('$ID','$Vehicle' ,'$Time','$Date','$Lat','$Long')");
if (mysql_errno()) {
header("HTTP/1.1 500 Internal Server Error");
echo $q.'\n';
echo mysql_error();
}
else
{
print json_encode("Inserted");
}
break;
}
?>
B4X:
Sub Button1_Click
Public ID As Int
ID = Rnd(1 ,4000)
Public vehicle As String
Dim InsertLocation As HttpJob
InsertLocation.Initialize("InsertNewP", Me)
InsertLocation.download2("http://www.**************.com/tracking/location_add.php", Array As String ("action", "InsertLocation","ID",ID, "Vehicle", vehicle, "Time", DateTime.Time(DateTime.Now),"Date",DateTime.Date(DateTime.Now),"Lat","lat_dene","Long","lblLon.Text"))
End Sub
Sub JobDone(Job As HttpJob)
ProgressDialogHide
If Job.Success Then
Dim res As String
res = Job.GetString
Log("Back from Job:" & Job.JobName )
Log("Response from server: " & res)
Dim parser As JSONParser
parser.Initialize(res)
Select Job.JobName
Case "InsertNewP"
'Do nothing
Msgbox("Location Sav3d","Loc Sav3d")
End Select
Else
ToastMessageShow("ERROR: " & Job.ErrorMessage, True)
End If
Job.Release
End Sub
Last edited: